BxBasePlayerHTML5.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // set visual mode
  53. switch ($iViewMode) {
  54. case BX_PLAYER_STANDARD:
  55. case BX_PLAYER_MINI:
  56. case BX_PLAYER_EMBED:
  57. default:
  58. $sInit = self::$CONF_STANDARD;
  59. }
  60. // attrs
  61. $aAttrsDefault = array(
  62. 'controls' => '',
  63. 'controlsList' => 'nodownload',
  64. 'preload' => 'none',
  65. 'autobuffer' => '',
  66. );
  67. $aAttrs = isset($aParams['attrs']) && is_array($aParams['attrs']) ? $aParams['attrs'] : array();
  68. $aAttrs = array_merge($aAttrsDefault, $aAttrs);
  69. if (isset($aParams['poster']) && is_string($aParams['poster']))
  70. $aAttrs['poster'] = $aParams['poster'];
  71. $sAttrs = bx_convert_array2attrs($aAttrs, false, isset($aParams['styles']) && is_string($aParams['styles']) ? $aParams['styles'] : false);
  72. // generate files list for HTML5 player
  73. $sFormat = getParam('sys_player_default_format');
  74. $aTypes = array(
  75. 'webm' => '<source type="video/webm; codecs=\'vp8, vorbis\'" src="{url}" />',
  76. 'mp4' => '<source type="video/mp4" src="{url}" />',
  77. );
  78. foreach ($aTypes as $s => $ss) {
  79. if (is_array($aParams[$s]) && !empty($aParams[$s][$sFormat]))
  80. $aParams[$s] = str_replace('{url}', $aParams[$s][$sFormat], $ss);
  81. elseif (is_array($aParams[$s]) && !empty($aParams[$s]['standard']))
  82. $aParams[$s] = str_replace('{url}', $aParams[$s]['standard'], $ss);
  83. elseif (is_string($aParams[$s]) && !empty($aParams[$s]))
  84. $aParams[$s] = str_replace('{url}', $aParams[$s], $ss);
  85. else
  86. $aParams[$s] = '';
  87. }
  88. // player code
  89. $sCode = $this->_replaceMarkers($sInit, array(
  90. 'attrs' => $sAttrs,
  91. 'webm' => $aParams['webm'],
  92. 'mp4' => $aParams['mp4'],
  93. ));
  94. return $sCode;
  95. }
  96. }
  97. /** @} */