Hello,
I had to setup the Open Standard Media (OSM) Player available from Mediafront DOT org, with playlist.
I post it here in the case it may be helpful to someone.
First, create a directory named ‘osmplayer’ under ‘protected/extensions’
Then, inside this directory, clone the GitHub repository of the osm player. You now should have a directory also named osmplayer inside the one you just created.
Also create a file named ‘OsmPlayerWidget.php’ with the following content :
<?php
class OsmPlayerWidget extends CWidget{
public $scriptUrl;
public $themeUrl;
public $themeDir;
public $theme='default';
public $scriptFile='/bin/osmplayer.compressed.js';
public $tagName = 'div';
public $width;
public $height;
public $playlist;
public $htmlOptions=array(
'id' => 'osmplayer'
);
public function init(){
if($this->width === null)
$this->width = 600;
if($this->height === null)
$this->height = 400;
$this->getOsmPath();
$this->registerFiles();
parent::init();
}
protected function getOsmPath(){
if($this->scriptUrl===null || $this->themeUrl===null){
$basePath=Yii::getPathOfAlias('application.extensions.osmplayer.osmplayer');
$am = new CAssetManager;
$am->excludeFiles=array('doc','jquery-ui','makefile','src');
$baseUrl=$am->publish($basePath);
if($this->scriptUrl===null)
$this->scriptUrl=$baseUrl.'';
if($this->themeUrl===null)
$this->themeUrl=$baseUrl.'/templates/'.$this->theme;
}
}
protected function registerFiles(){
$cs=Yii::app()->getClientScript();
/* Register OSM */
if(is_string($this->scriptFile)){
$cs->registerScriptFile($this->scriptUrl.'/'.$this->scriptFile, CClientScript::POS_HEAD);
} elseif(is_array($this->scriptFile)){
foreach($this->scriptFile as $file){
$cs->registerScriptFile($this->scriptUrl.'/'.$file, CClientScript::POS_HEAD);
}
}
if($this->themeDir===null)
$this->themeDir=Yii::getPathOfAlias('application.extensions.osmplayer.osmplayer.templates.'.$this->theme);
if(is_dir($this->themeDir) && is_readable($this->themeDir)){
/* Register CSS */
foreach(glob($this->themeDir.'/css/*.[cC][sS][sS]') as $file){
if(is_file($file) && is_readable($file))
$cs->registerCssFile($this->themeUrl.'/css/'.basename($file));
}
/* Register JS */
foreach(glob($this->themeDir.'/js/*.[jJ][sS]') as $file){
if(is_file($file) && is_readable($file))
$cs->registerScriptFile($this->themeUrl.'/js/'.basename($file), CClientScript::POS_HEAD);
}
}
}
public function run(){
if($this->playlist === null)
$this->playlist = $this->scriptUrl.'/playlist.xml';
$options = "playlist: '{$this->playlist}'";
if($this->width !== false)
$options.= ",\nwidth: '{$this->width}px'";
if($this->height !== false)
$options.= ",\nheight: '{$this->height}px'";
Yii::app()->getClientScript()->registerScript('jsOsm',
"jQuery('{$this->tagName}#{$this->htmlOptions['id']}').osmplayer({
logo: '{$this->scriptUrl}/logo.png',
swfplayer: '{$this->scriptUrl}/minplayer/flash/minplayer.swf',
$options
});",
CClientScript::POS_END
);
echo CHtml::openTag($this->tagName,$this->htmlOptions);
echo CHtml::closeTag($this->tagName);
}
}
You now can call the widget from your view with the following code :
$this->widget('application.extensions.osmplayer.OsmPlayerWidget', array(
'playlist' => Yii::app()->createUrl('controller/playlist.xml'),
'height' => 400,
'width' => false
));
In the controller, in order to generate the playlist XML:
public function actionPlaylist(){
$this->layout = 'playlist';
$this->render('playlist');
}
The layout :
[html]
<?php echo ‘<?xml version=“1.0” encoding=“UTF-8”?>’;?>
<playlist version="1" xmlns="URL NOT ALLOWED BY YII FORUM SILLY RULE - SEE ATTACHED FILE PLAYLIST.PHP">
<trackList>
<?php echo $content;?>
</trackList>
</playlist>
[/html]
The view :
[html]
<track>
<title>Video Title</title>
<location><?php echo Yii::app()->request->baseUrl;?>/path/to/video-1.mov</location>
<image><?php echo Yii::app()->request->baseUrl;?>/path/to/thumbnail-1.png</image>
</track>
(… repeat as needed)
[/html]
A final note: you may have noticed that the player needs the ‘.xml’ extension of the playlist URL. This requires a specific rule in the urlManager component in ‘config/main.php’ :
'controller/playlist.xml' => 'controller/playlist'
There’s certainly much room for improvement, but that’s a start
Happy coding !