<?php /* * JWplayer widget class file. * JWplayer extends CWidget * @version 1.0 - 20110516 * @author skarah <skarah@mail.ru> * @copyright Copyright © 2011 skarah * @license New BSD License http://www.opensource.org/licenses/bsd-license.php */ class JWplayer extends CWidget { /** * -. * * @var array */ public $_options = array( // ID 'id' => 'playerID', // 'width' => 480, // 'height' => 270, // 'file' => '', // - 'flashplayer' => '', ); /** * options. * * @var array */ public $options = array(); /** * assets. */ public function init() { $this->publishAssets(); } /** * */ public function run() { /* * */ extract($this->_options); /* * */ extract($this->options); echo "<div id='mediaplayer'></div> <script type=\"text/javascript\"> jwplayer('mediaplayer').setup({ 'id': '{$id}', 'width': '{$width}', 'height': '{$height}', 'file': '{$file}', 'flashplayer': '{$flashplayer}', 'modes': [{type: 'flash', src: '{$flashplayer}'}] }); </script>"; } protected function publishAssets() { /* * assets */ $assets = dirname(__FILE__) . '/assets'; $baseUrl = Yii::app()->assetManager->publish($assets); if (is_dir($assets)) { /* * - */ $this->_options['flashplayer'] = $baseUrl . '/player.swf'; /* * js */ Yii::app()->clientScript->registerScriptFile($baseUrl . '/jwplayer.js', CClientScript::POS_HEAD); Yii::app()->clientScript->registerScriptFile($baseUrl . '/swfobject.js', CClientScript::POS_HEAD); } else { throw new Exception(' JWplayer: assets .'); } } }
$this->widget('application.extensions.jwplayer.JWplayer', array( 'options' => array( 'file' => '/path_to/my_mp4file.mp4' ), ));
Source: https://habr.com/ru/post/119368/
All Articles