EllisLab text mark
Advanced Search
     
jwplayer made easy
Posted: 18 December 2011 11:23 PM   [ Ignore ]
Avatar
Joined: 2009-05-17
1415 posts

I use jwplayer to play videos on my website. It’s nice because it plays with Flash or HTML5, and HTML5 is necessary if you want to have videos that people can watch on their iPads. So I made this little library to make adding videos in views super easy:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class 
Video_player
{
 
/*
  * DEFAULTS
  * ----------------------------------------------------
  * Although only 'flashplayer' is mandatory, the other 
  * elements of the defaults array are essential to 
  * maintain a uniform look for all video players on my site.
  */
 
private $defaults    = array(
  
'config'      => '/jwplayer/config_xml/576x324.xml',
  
'width'       => '576',
  
'height'      => '324',
  
'flashplayer' => '/jwplayer/player.swf'
 
);

 private 
$id          1;

 public function 
jw_embedder$params = array() )
 
{
  $config 
array_merge$this->defaults$params );

  
$output '
   <div id="video-container-' 
$this->id '">
    Loading video ...
   </div>
   [removed]
    jwplayer("video-container-' 
$this->id '").setup({' "\n";

  
$num count$config );

  
$i 1;
  
  foreach( 
$config as $k => $v )
  
{
   $output 
.= '"' $k '": "' $v '"';

   
$output .= ( $i != $num ) ? ",\n" "";

   
$i++;
  
}

  $output 
.= '     
    });
   [removed]
  '
;

  
$this->id++;

  return 
$output;
 
}
}

/* End of file video_player.php */
/* Location: .application/libraries/video_player.php */ 

This is the XML config:

<?xml version='1.0' encoding='UTF-8' ?>
<config>
 <
controlbar>over</controlbar>
 <
skin>http://www.mysite.com/jwplayer/skins/facebook.zip</skin>
 
<dock>false</dock>
 <
autostart>false</autostart>
 <
height>324</height>
 <
width>576</width>
 <
icons>true</icons>
 <
playlist.position>none</playlist.position>
 <
playlistsize>180</playlistsize>
 <
repeat>none</repeat>
 <
shuffle>false</shuffle>
 <
bufferlength>1</bufferlength>
 <
smoothing>true</smoothing>
 <
stretching>uniform</stretching>
 <
wmode>opaque</wmode>
 <
mute>false</mute>
 <
volume>90</volume>
 <
screencolor>000000</screencolor>
</
config

And usage in the view:

echo $this->video_player->jw_embedder( array(
 
'file'  => 'http://www.mysite.com/video/whatever.mov',
 
'image' => 'http://www.mysite.com/img/video/whatever.jpg'
)); 

You’ll of course have to have jwplayer and call jwplayer.js in the head, and load the video player library in your controller:

$this->load->library('video_player'); 

That’s it. Have fun. Oh, and the [removed] is the opening and closing script tags.

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application

 
Posted: 08 October 2012 03:35 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-09-15
3 posts

A problem:-S


The video could not be loaded, either because the server or network failed or because the format is not supported: http://localhost/alma/images/videos/video.webm

echo $this->video_player->jw_embedder( array(
  
'file'  => "http://localhost/alma/images/videos/video.webm",
 
'image' => 'http://localhost/alma/images/slider/1.jpg'
)); 
 
Posted: 08 October 2012 06:04 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2011-01-31
384 posts

Many servers don’t know the webm media type. You have to add it through htaccess or ask your hosting provider to do so.

 Signature 

NetID