BxBasePlayerHTML5.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. * Minimal view initialization params
  26. */
  27. protected static $CONF_MINI = "";
  28. /**
  29. * Embed view initialization params
  30. */
  31. protected static $CONF_EMBED = "";
  32. /**
  33. * Available player languages
  34. */
  35. protected static $CONF_LANGS = array();
  36. protected $_oTemplate;
  37. protected $_bJsCssAdded = false;
  38. public function __construct ($aObject, $oTemplate)
  39. {
  40. parent::__construct ($aObject);
  41. if ($oTemplate)
  42. $this->_oTemplate = $oTemplate;
  43. else
  44. $this->_oTemplate = BxDolTemplate::getInstance();
  45. }
  46. public function getCodeAudio ($iViewMode, $aParams, $bDynamicMode = false)
  47. {
  48. // TODO:
  49. }
  50. public function getCodeVideo ($iViewMode, $aParams, $bDynamicMode = false)
  51. {
  52. $sInit = self::$CONF_STANDARD;
  53. $sClass = 'bx-player';
  54. // set visual mode
  55. switch ($iViewMode) {
  56. case BX_PLAYER_MINI:
  57. $sClass .= ' bx-player-mini';
  58. break;
  59. case BX_PLAYER_EMBED:
  60. $sClass .= ' bx-player-embed';
  61. break;
  62. case BX_PLAYER_STANDARD:
  63. default:
  64. $sClass .= ' bx-player-standard';
  65. }
  66. // attrs
  67. $aAttrsDefault = array(
  68. 'controls' => '',
  69. 'controlsList' => 'nodownload',
  70. 'preload' => 'none',
  71. 'autobuffer' => '',
  72. 'class' => $sClass,
  73. );
  74. $aAttrs = isset($aParams['attrs']) && is_array($aParams['attrs']) ? $aParams['attrs'] : array();
  75. $aAttrs = array_merge($aAttrsDefault, $aAttrs);
  76. if (isset($aParams['poster']) && is_string($aParams['poster']))
  77. $aAttrs['poster'] = $aParams['poster'];
  78. $sAttrs = bx_convert_array2attrs($aAttrs, false, isset($aParams['styles']) && is_string($aParams['styles']) ? $aParams['styles'] : false);
  79. // generate files list for HTML5 player
  80. $sFormat = getParam('sys_player_default_format');
  81. $aTypes = array(
  82. 'webm' => '<source type="video/webm; codecs=\'vp8, vorbis\'" src="{url}" />',
  83. 'mp4' => '<source type="video/mp4" src="{url}" />',
  84. );
  85. foreach ($aTypes as $s => $ss) {
  86. if (!isset($aParams[$s]))
  87. continue;
  88. if (is_array($aParams[$s]) && !empty($aParams[$s][$sFormat]))
  89. $aParams[$s] = str_replace('{url}', $aParams[$s][$sFormat], $ss);
  90. elseif (is_array($aParams[$s]) && !empty($aParams[$s]['sd']))
  91. $aParams[$s] = str_replace('{url}', $aParams[$s]['sd'], $ss);
  92. elseif (is_string($aParams[$s]) && !empty($aParams[$s]))
  93. $aParams[$s] = str_replace('{url}', $aParams[$s], $ss);
  94. else
  95. $aParams[$s] = '';
  96. }
  97. // player code
  98. $sCode = $this->_replaceMarkers($sInit, array(
  99. 'attrs' => $sAttrs,
  100. 'webm' => isset($aParams['webm']) ? $aParams['webm'] : '',
  101. 'mp4' => isset($aParams['mp4']) ? $aParams['mp4'] : '',
  102. ));
  103. return $sCode;
  104. }
  105. }
  106. /** @} */