UNPKG

@tycoonsystems/tycoon-modules

Version:
1 lines 1.87 kB
import{checkiOS}from"@tycoonsystems/tycoon-modules/util";function _callback_onAutoplayBlocked(){}function isSafari(){try{var e,o;return window?(e=-1<window.navigator.userAgent.toLowerCase().indexOf("chrome"),o=-1<window.navigator.userAgent.toLowerCase().indexOf("safari"),!e&&o):null}catch(e){return null}}const setAndPlay=(e,o,r)=>{r?.src&&(setSource(e,o,r),ensureAutoPlay(r.play,r))},setSource=(e,o,r)=>{r.src({src:e,type:"hls"===o?"application/x-mpegURL":"application/dash+xml"})},ensureSetSource=(e,o,r,t,n,c)=>{console.log("current src",e?.currentSrc(),"intent src",o?.src),(""===e?.currentSrc()&&""!==o?.src||n)&&(r="live"==(n="Live"==(o=r)?.__typename?"live":"static")||checkiOS()?"hls":"mpd",console.log("use Record",o),o)&&t&&(n="static"==n?t+"/video/"+o[r]:""+o?.meta?.channel?.playbackUrl)&&(console.log("Do Set Src",e,n),e.src({src:n,type:"hls"==r?"application/x-mpegURL":"application/dash+xml"}),"function"==typeof c)&&c()};function ensureAutoPlay(e,o,r){try{if(!window?.imaPlaying){console.log("Ensure Auto Play play()");var t=window.Promise?window.Promise.toString():"";if(-1!==t.indexOf("function Promise()")||-1!==t.indexOf("function ZoneAwarePromise()")){try{window?.userInteracted||videoPlayer.muted(!0)}catch(e){}return e().catch(function(e){return"NotAllowedError"==e.name?(console.error("_checkAutoPlay: error.name:","NotAllowedError"),r&&r()):"AbortError"==e.name&&isSafari()?(console.error("_checkAutoPlay: AbortError (Safari)"),r&&r()):console.error("_checkAutoPlay: something else happened",e),e}).then(function(e){console.log("_checkAutoPlay: then",e)})}console.error("_checkAutoplay: promise could not work in your browser ",e)}}catch(e){return console.log(e),e}}export default{ensureAutoPlay:ensureAutoPlay,ensureSetSource:ensureSetSource,setAndPlay:setAndPlay,setSource:setSource};export{setAndPlay,setSource,ensureSetSource,ensureAutoPlay};