410410 var initDecoder = this . initDecoder ( playParams ) ;
411411 // 初始化播放器
412412 _this . loadingSet ( 0 , { text : '初始化播放器...' } ) ;
413+ if ( playParams . autoplay ) {
414+ _this . play ( )
415+ }
413416 if ( isPromise ( initDecoder ) ) {
414417 initDecoder . then ( function ( data ) {
415418 _this . loadingSet ( 0 , { text : '初始化完成' } ) ;
416419 // setTimeout(function () {
417420 // _this.play(playParams);
418421 // }, 100)
419- var getRealUrl = _this . getRealUrl ( playParams ) ;
420- getRealUrl . then ( function ( data ) {
421- _this . play ( playParams ) ;
422- } )
422+ // var getRealUrl = _this.getRealUrl(playParams);
423+ // getRealUrl.then(function (data) {
424+ // _this.play(playParams);
425+ // })
423426 } )
424427 }
425428 // debugger
536539 } ) ;
537540 var appInfoSuccess = function ( data ) {
538541 if ( data . retcode === 0 && data . data ) {
539- console . log ( "data" , data ) ;
540542 appKey = data . data . appKey ;
541543 }
542544 // 上报一次本地信息
15681570 }
15691571 }
15701572
1571- EZUIPlayer . prototype . play = function ( i ) {
1573+ EZUIPlayer . prototype . play = function ( data ) {
15721574 // debugger
15731575 //var index = params.index;
15741576 if ( ! ! window [ 'CKobject' ] ) {
@@ -1591,148 +1593,155 @@
15911593 var audioId = 0
15921594 if ( playParams && playParams . audioId ) {
15931595 audioId = playParams . audioId ;
1594- } else if ( playParams && playParams . audioId === - 1 ) {
1596+ } else if ( playParams && playParams . audioId === - 1 ) {
15951597 audioId = undefined ;
15961598 }
1597-
1598- var _this = this ;
1599- function getPlayParams ( url ) {
1600- var websocketConnectUrl = url . split ( '?' ) [ 0 ] . replace ( '/live' , '' ) . replace ( '/playback' , '' ) ;
1601- // console.log("playParams,",playParams,playParams.env.wsUrl)
1602- // if(playParams && playParams.env && playParams.env.wsUrl){
1603- // websocketConnectUrl= playParams.env.wsUrl;
1604- // }
1605- console . log ( "_this.opt.sources." , _this . opt . sources )
1606- var websocketStreamingParam = ( url . indexOf ( '/live' ) === - 1 ? ( url . indexOf ( 'cloudplayback' ) !== - 1 ? '/cloudplayback?' : '/playback?' ) : '/live?' ) + url . split ( '?' ) [ 1 ] ;
1607- // 本地回放仅支持主码流 - 2019-11-05 修订
1608- if ( websocketStreamingParam . indexOf ( '/playback' ) !== - 1 ) {
1609- websocketStreamingParam = websocketStreamingParam . replace ( "stream=2" , 'stream=1' ) ;
1610- }
1611- // 本地回放仅支持主码流
1612- return { websocketConnectUrl : websocketConnectUrl , websocketStreamingParam : websocketStreamingParam }
1599+ if ( typeof data === 'string' ) {
1600+ playParams . url = data ;
1601+ } else if ( typeof data === 'object' ) {
1602+ playParams = Object . assign ( playParams , data ) ;
16131603 }
1614- _this . opt . sources . forEach ( function ( item , index ) {
1615- if ( getQueryString ( 'dev' , item ) || item . indexOf ( 'ws' ) !== - 1 ) {
1616- _this . log ( "开始播放, 第" + ( index + 1 ) + '路,' + '地址:' + item ) ;
1617- _this . loadingSet ( index , { text : '准备播放...' , color : '#fff' } )
1618- // 设置秘钥 - 如果地址中包含秘钥参数,播放前配置到JSPlugin对应实例中
1619- var validateCode = getQueryString ( 'checkCode' , item ) ;
1620- if ( validateCode ) {
1621- _this . log ( '设置秘钥,视频路数:' + ( index + 1 ) + '验证码:' + validateCode )
1622- _this . jSPlugin . JS_SetSecretKey ( index , validateCode ) ;
1604+ var getRealUrl = this . getRealUrl ( playParams ) ;
1605+ var _this = this ;
1606+ getRealUrl . then ( function ( ) {
1607+ function getPlayParams ( url ) {
1608+ var websocketConnectUrl = url . split ( '?' ) [ 0 ] . replace ( '/live' , '' ) . replace ( '/playback' , '' ) ;
1609+ // console.log("playParams,",playParams,playParams.env.wsUrl)
1610+ // if(playParams && playParams.env && playParams.env.wsUrl){
1611+ // websocketConnectUrl= playParams.env.wsUrl;
1612+ // }
1613+ console . log ( "_this.opt.sources." , _this . opt . sources )
1614+ var websocketStreamingParam = ( url . indexOf ( '/live' ) === - 1 ? ( url . indexOf ( 'cloudplayback' ) !== - 1 ? '/cloudplayback?' : '/playback?' ) : '/live?' ) + url . split ( '?' ) [ 1 ] ;
1615+ // 本地回放仅支持主码流 - 2019-11-05 修订
1616+ if ( websocketStreamingParam . indexOf ( '/playback' ) !== - 1 ) {
1617+ websocketStreamingParam = websocketStreamingParam . replace ( "stream=2" , 'stream=1' ) ;
16231618 }
1624- var playST = new Date ( ) . getTime ( ) ;
1625-
1626- var wsUrl = ''
1627- var wsParams = ''
1628- if ( _this . playParams && _this . playParams . hasOwnProperty ( 'userName' ) && _this . playParams . hasOwnProperty ( 'password' ) ) {
1629- console . log ( "this.opt." )
1630- wsUrl = item . split ( '?' ) [ 0 ] ;
1631- wsParams = {
1632- sessionID : getQueryString ( 'sessionID' , item ) ,
1619+ // 本地回放仅支持主码流
1620+ return { websocketConnectUrl : websocketConnectUrl , websocketStreamingParam : websocketStreamingParam }
1621+ }
1622+ _this . opt . sources . forEach ( function ( item , index ) {
1623+ if ( getQueryString ( 'dev' , item ) || item . indexOf ( 'ws' ) !== - 1 ) {
1624+ _this . log ( "开始播放, 第" + ( index + 1 ) + '路,' + '地址:' + item ) ;
1625+ _this . loadingSet ( index , { text : '准备播放...' , color : '#fff' } )
1626+ // 设置秘钥 - 如果地址中包含秘钥参数,播放前配置到JSPlugin对应实例中
1627+ var validateCode = getQueryString ( 'checkCode' , item ) ;
1628+ if ( validateCode ) {
1629+ _this . log ( '设置秘钥,视频路数:' + ( index + 1 ) + '验证码:' + validateCode )
1630+ _this . jSPlugin . JS_SetSecretKey ( index , validateCode ) ;
16331631 }
1634- } else {
1635- wsUrl = getPlayParams ( item ) . websocketConnectUrl ;
1636- wsParams = {
1637- playURL : getPlayParams ( item ) . websocketStreamingParam
1632+ var playST = new Date ( ) . getTime ( ) ;
1633+
1634+ var wsUrl = ''
1635+ var wsParams = ''
1636+ if ( _this . playParams && _this . playParams . hasOwnProperty ( 'userName' ) && _this . playParams . hasOwnProperty ( 'password' ) ) {
1637+ wsUrl = item . split ( '?' ) [ 0 ] ;
1638+ wsParams = {
1639+ sessionID : getQueryString ( 'sessionID' , item ) ,
1640+ }
1641+ } else {
1642+ wsUrl = getPlayParams ( item ) . websocketConnectUrl ;
1643+ wsParams = {
1644+ playURL : getPlayParams ( item ) . websocketStreamingParam
1645+ }
16381646 }
1639- }
1640- _this . jSPlugin . JS_Play ( wsUrl , wsParams , index ) . then ( function ( ) {
1641- _this . log ( '播放成功,当前播放第' + ( index + 1 ) + '路' ) ;
1642- _this . loadingSet ( index , { text : '播放成功...' } ) ;
1643- //单次播放日志上报
1644- ezuikitDclog ( {
1645- systemName : PERFORMANCE_EZUIKIT ,
1646- bn : 2 ,
1647- browser : JSON . stringify ( getBrowserInfo ( ) ) ,
1648- duration : new Date ( ) . getTime ( ) - playST ,
1649- rt : 200 ,
1650- } )
1651- // 播放成功
1652- ezuikitDclog ( {
1653- systemName : PERFORMANCE_EZUIKIT ,
1654- bn : 99 ,
1655- browser : JSON . stringify ( getBrowserInfo ( ) ) ,
1656- duration : new Date ( ) . getTime ( ) - playStartTime ,
1657- rt : 200 ,
1658- } )
1659- _this . loadingEnd ( index ) ;
1660- // 默认开启声音
1661- // 默认开启第一路声音
1662- if ( typeof ( audioId ) !== "undefined" && audioId === index ) {
1663- _this . log ( "默认开启第1路声音" ) ;
1664- setTimeout ( function ( ) {
1665- var openSoundRT = _this . jSPlugin . JS_OpenSound ( 0 ) ;
1666- console . log ( "openSoundRT" , openSoundRT )
1667- openSoundRT . then ( function ( data ) {
1668- _this . log ( '开启声音成功' , data )
1669- } )
1670- . catch ( function ( err ) {
1671- _this . log ( '开启声音失败' , 'error' , err )
1647+ _this . jSPlugin . JS_Play ( wsUrl , wsParams , index ) . then ( function ( ) {
1648+ _this . log ( '播放成功,当前播放第' + ( index + 1 ) + '路' ) ;
1649+ _this . loadingSet ( index , { text : '播放成功...' } ) ;
1650+ //单次播放日志上报
1651+ ezuikitDclog ( {
1652+ systemName : PERFORMANCE_EZUIKIT ,
1653+ bn : 2 ,
1654+ browser : JSON . stringify ( getBrowserInfo ( ) ) ,
1655+ duration : new Date ( ) . getTime ( ) - playST ,
1656+ rt : 200 ,
1657+ } )
1658+ // 播放成功
1659+ ezuikitDclog ( {
1660+ systemName : PERFORMANCE_EZUIKIT ,
1661+ bn : 99 ,
1662+ browser : JSON . stringify ( getBrowserInfo ( ) ) ,
1663+ duration : new Date ( ) . getTime ( ) - playStartTime ,
1664+ rt : 200 ,
1665+ } )
1666+ _this . loadingEnd ( index ) ;
1667+ // 默认开启声音
1668+ // 默认开启第一路声音
1669+ if ( typeof ( audioId ) !== "undefined" && audioId === index ) {
1670+ _this . log ( "默认开启第1路声音" ) ;
1671+ setTimeout ( function ( ) {
1672+ var openSoundRT = _this . jSPlugin . JS_OpenSound ( 0 ) ;
1673+ console . log ( "openSoundRT" , openSoundRT )
1674+ openSoundRT . then ( function ( data ) {
1675+ _this . log ( '开启声音成功' , data )
16721676 } )
1673- } , 100 )
1674- }
1675- // 播放成功回调
1676- if ( playParams && playParams . handleSuccess ) {
1677- playParams . handleSuccess ( ) ;
1678- }
1679- //
1680- // 播放成功日志上报
1681- var PlTp = 1 ;
1682- if ( playParams && playParams . url ) {
1683- if ( playParams . url . indexOf ( 'rec' ) !== - 1 ) {
1684- PlTp = 2 ;
1677+ . catch ( function ( err ) {
1678+ _this . log ( '开启声音失败' , 'error' , err )
1679+ } )
1680+ } , 100 )
1681+ }
1682+ // 播放成功回调
1683+ if ( playParams && playParams . handleSuccess ) {
1684+ playParams . handleSuccess ( ) ;
1685+ }
1686+ //
1687+ // 播放成功日志上报
1688+ var PlTp = 1 ;
1689+ if ( playParams && playParams . url ) {
1690+ if ( playParams . url . indexOf ( 'rec' ) !== - 1 ) {
1691+ PlTp = 2 ;
1692+ }
1693+ }
1694+ dclog ( {
1695+ systemName : PLAY_MAIN ,
1696+ playurl : encodeURIComponent ( item ) ,
1697+ Time : ( new Date ( ) ) . Format ( 'yyyy-MM-dd hh:mm:ss.S' ) ,
1698+ Enc : 0 , // 0 不加密 1 加密
1699+ PlTp : PlTp , // 1 直播 2 回放
1700+ Via : 2 , // 2 服务端取流
1701+ ErrCd : 0 ,
1702+ OpId : uuid ( ) ,
1703+ Cost : ( new Date ( ) ) . getTime ( ) - _this . initTime , // 毫秒数
1704+ Serial : getQueryString ( 'dev' , item ) ,
1705+ Channel : getQueryString ( 'chn' , item ) ,
1706+ } ) ;
1707+ } , function ( err ) {
1708+ _this . log ( '播放失败' + JSON . stringify ( err ) , 'error' ) ;
1709+ var errorInfo = JSON . parse ( _this . errorCode ) . find ( function ( item ) { return item . detailCode . substr ( - 4 ) == err . oError . errorCode } ) ;
1710+ ezuikitDclog ( {
1711+ systemName : PERFORMANCE_EZUIKIT ,
1712+ bn : 2 ,
1713+ browser : JSON . stringify ( getBrowserInfo ( ) ) ,
1714+ duration : new Date ( ) . getTime ( ) - playStartTime ,
1715+ rt : err . oError ? err . oError . errorCode : 500 ,
1716+ msg : errorInfo ? errorInfo . description : '播放过程其他错误'
1717+ } )
1718+ var msg = errorInfo ? errorInfo . description : '播放过程其他错误' ;
1719+ _this . loadingSet ( index , { text : msg , color : 'red' } ) ;
1720+ dclog ( {
1721+ systemName : PLAY_MAIN ,
1722+ playurl : encodeURIComponent ( item ) ,
1723+ cost : - 1 ,
1724+ ErrCd : ( err && err . oError && err . oError . errorCode && ( err . oError . errorCode + "" ) . substr ( - 4 ) ) || - 1 ,
1725+ Via : 2 ,
1726+ OpId : uuid ( ) ,
1727+ Serial : getQueryString ( 'dev' , item ) ,
1728+ Channel : getQueryString ( 'chn' , item ) ,
1729+ } ) ;
1730+ if ( playParams && playParams . handleError ) {
1731+ var errorInfo = JSON . parse ( _this . errorCode ) . find ( function ( item ) { return item . detailCode . substr ( - 4 ) == err . oError . errorCode } )
1732+ playParams . handleError ( { retcode : err . oError . errorCode , msg : errorInfo ? errorInfo . description : '其他错误' } ) ;
16851733 }
1686- }
1687- dclog ( {
1688- systemName : PLAY_MAIN ,
1689- playurl : encodeURIComponent ( item ) ,
1690- Time : ( new Date ( ) ) . Format ( 'yyyy-MM-dd hh:mm:ss.S' ) ,
1691- Enc : 0 , // 0 不加密 1 加密
1692- PlTp : PlTp , // 1 直播 2 回放
1693- Via : 2 , // 2 服务端取流
1694- ErrCd : 0 ,
1695- OpId : uuid ( ) ,
1696- Cost : ( new Date ( ) ) . getTime ( ) - _this . initTime , // 毫秒数
1697- Serial : getQueryString ( 'dev' , item ) ,
1698- Channel : getQueryString ( 'chn' , item ) ,
1699- } ) ;
1700- } , function ( err ) {
1701- _this . log ( '播放失败' + JSON . stringify ( err ) , 'error' ) ;
1702- var errorInfo = JSON . parse ( _this . errorCode ) . find ( function ( item ) { return item . detailCode . substr ( - 4 ) == err . oError . errorCode } ) ;
1703- ezuikitDclog ( {
1704- systemName : PERFORMANCE_EZUIKIT ,
1705- bn : 2 ,
1706- browser : JSON . stringify ( getBrowserInfo ( ) ) ,
1707- duration : new Date ( ) . getTime ( ) - playStartTime ,
1708- rt : err . oError ? err . oError . errorCode : 500 ,
1709- msg : errorInfo ? errorInfo . description : '播放过程其他错误'
17101734 } )
1711- var msg = errorInfo ? errorInfo . description : '播放过程其他错误' ;
1712- _this . loadingSet ( index , { text : msg , color : 'red' } ) ;
1713- dclog ( {
1714- systemName : PLAY_MAIN ,
1715- playurl : encodeURIComponent ( item ) ,
1716- cost : - 1 ,
1717- ErrCd : ( err && err . oError && err . oError . errorCode && ( err . oError . errorCode + "" ) . substr ( - 4 ) ) || - 1 ,
1718- Via : 2 ,
1719- OpId : uuid ( ) ,
1720- Serial : getQueryString ( 'dev' , item ) ,
1721- Channel : getQueryString ( 'chn' , item ) ,
1722- } ) ;
1723- if ( playParams && playParams . handleError ) {
1724- var errorInfo = JSON . parse ( _this . errorCode ) . find ( function ( item ) { return item . detailCode . substr ( - 4 ) == err . oError . errorCode } )
1725- playParams . handleError ( { retcode : err . oError . errorCode , msg : errorInfo ? errorInfo . description : '其他错误' } ) ;
1726- }
1727- } )
17281735
1729- } else {
1730- if ( isJSON ( item ) && JSON . parse ( item ) . msg ) {
1731- _this . loadingSet ( index , { text : JSON . parse ( item ) . msg , color : 'red' } )
1736+ } else {
1737+ if ( isJSON ( item ) && JSON . parse ( item ) . msg ) {
1738+ _this . loadingSet ( index , { text : JSON . parse ( item ) . msg , color : 'red' } )
1739+ }
17321740 }
1733- }
1741+ } )
17341742 } )
17351743 }
1744+
17361745
17371746 } ;
17381747 EZUIPlayer . prototype . initDecoder = function ( playParams ) {
17651774 _this . jSPlugin . JS_SetWindowControlCallback ( {
17661775 windowEventSelect : function ( iWndIndex ) { //插件选中窗口回调
17671776 iWind = iWndIndex ;
1768- console . log ( iWndIndex ) ;
17691777 } ,
17701778 pluginErrorHandler : function ( iWndIndex , iErrorCode , oError ) { //插件错误回调
17711779 console . log ( iWndIndex , iErrorCode , oError ) ;
0 commit comments