• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
jwplayer made easy

#1
[eluser]skunkbad[/eluser]
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:
Code:
<?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-&gt;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:
Code:
&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
<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:
Code:
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:
Code:
$this->load->library('video_player');

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

#2
[eluser]sarbaz[/eluser]
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
Code:
echo $this->video_player->jw_embedder( array(
  'file'  => "http://localhost/alma/images/videos/video.webm",
'image' => 'http://localhost/alma/images/slider/1.jpg'
));

#3
[eluser]osci[/eluser]
Many servers don't know the webm media type. You have to add it through htaccess or ask your hosting provider to do so.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.