1
0

BxBasePlayerHTML5.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Basic HTML5 player representation.
  11. * @see BxDolPlayer
  12. */
  13. class BxBasePlayerHTML5 extends BxDolPlayer
  14. {
  15. /**
  16. * Standard view initialization params
  17. */
  18. protected static $CONF_STANDARD = "
  19. <video {attrs}>
  20. {webm}
  21. {mp4}
  22. </video>
  23. ";
  24. /**
  25. * Standard view initialization params for audio
  26. */
  27. protected static $CONF_STANDARD_AUDIO = "
  28. <audio {attrs}>
  29. {mp3}
  30. </audio>
  31. ";
  32. /**
  33. * Minimal view initialization params
  34. */
  35. protected static $CONF_MINI = "";
  36. /**
  37. * Embed view initialization params
  38. */
  39. protected static $CONF_EMBED = "";
  40. /**
  41. * Available player languages
  42. */
  43. protected static $CONF_LANGS = array();
  44. protected $_oTemplate;
  45. protected $_bJsCssAdded = false;
  46. public function __construct ($aObject, $oTemplate)
  47. {
  48. parent::__construct ($aObject);
  49. if ($oTemplate)
  50. $this->_oTemplate = $oTemplate;
  51. else
  52. $this->_oTemplate = BxDolTemplate::getInstance();
  53. }
  54. public function getCodeAudio ($iViewMode, $aParams, $bDynamicMode = false)
  55. {
  56. return $this->_getCode(self::$CONF_STANDARD_AUDIO, 'bx-player', $iViewMode, $aParams, $bDynamicMode);
  57. }
  58. public function getCodeVideo ($iViewMode, $aParams, $bDynamicMode = false)
  59. {
  60. return $this->_getCode(self::$CONF_STANDARD, 'bx-player', $iViewMode, $aParams, $bDynamicMode);
  61. }
  62. protected function _getCode ($sInit, $sClass, $iViewMode, $aParams, $bDynamicMode = false)
  63. {
  64. // set visual mode
  65. switch ($iViewMode) {
  66. case BX_PLAYER_MINI:
  67. $sClass .= ' bx-player-mini';
  68. break;
  69. case BX_PLAYER_EMBED:
  70. $sClass .= ' bx-player-embed';
  71. break;
  72. case BX_PLAYER_STANDARD:
  73. default:
  74. $sClass .= ' bx-player-standard';
  75. }
  76. // attrs
  77. $aAttrsDefault = array(
  78. 'controls' => '',
  79. 'controlsList' => 'nodownload',
  80. 'preload' => 'none',
  81. 'autobuffer' => '',
  82. 'class' => $sClass,
  83. );
  84. $aAttrs = isset($aParams['attrs']) && is_array($aParams['attrs']) ? $aParams['attrs'] : array();
  85. $aAttrs = array_merge($aAttrsDefault, $aAttrs);
  86. if (isset($aParams['poster']) && is_string($aParams['poster']))
  87. $aAttrs['poster'] = $aParams['poster'];
  88. $sAttrs = bx_convert_array2attrs($aAttrs, false, isset($aParams['styles']) && is_string($aParams['styles']) ? $aParams['styles'] : false);
  89. // generate files list for HTML5 player
  90. $sFormat = getParam('sys_player_default_format');
  91. $aTypes = array(
  92. 'webm' => '<source type="video/webm; codecs=\'vp8, vorbis\'" src="{url}" />',
  93. 'mp4' => '<source type="video/mp4" src="{url}" />',
  94. 'mp3' => '<source type="audio/mpeg" src="{url}" />',
  95. );
  96. foreach ($aTypes as $s => $ss) {
  97. if (!isset($aParams[$s]))
  98. continue;
  99. if (is_array($aParams[$s]) && !empty($aParams[$s][$sFormat]))
  100. $aParams[$s] = str_replace('{url}', $aParams[$s][$sFormat], $ss);
  101. elseif (is_array($aParams[$s]) && !empty($aParams[$s]['sd']))
  102. $aParams[$s] = str_replace('{url}', $aParams[$s]['sd'], $ss);
  103. elseif (is_string($aParams[$s]) && !empty($aParams[$s]))
  104. $aParams[$s] = str_replace('{url}', $aParams[$s], $ss);
  105. else
  106. $aParams[$s] = '';
  107. }
  108. // player code
  109. $sCode = $this->_replaceMarkers($sInit, array(
  110. 'attrs' => $sAttrs,
  111. 'webm' => isset($aParams['webm']) ? $aParams['webm'] : '',
  112. 'mp4' => isset($aParams['mp4']) ? $aParams['mp4'] : '',
  113. 'mp3' => isset($aParams['mp3']) ? $aParams['mp3'] : '',
  114. ));
  115. return $sCode;
  116. }
  117. }
  118. /** @} */