阿里云视频播放

  配置文件:
  /*阿里云视频相关配置 */
  vodAccessKeyId: 'LTAI0OVcwKRNQupi',
vodSecretAccessKey: 'EQtWDv89LqUXwRjBd044UpZmIoEgCq',
vodEndpoint: 'http://vod.cn-shanghai.aliyuncs.com',
vodApiVersion: '2017-03-21'

控制层:
async getvideoplayauthAction() {
var VideoId = this. param( "vid");
if ( VideoId && VideoId.length > 0) {
var client = new RPCClient({
accessKeyId: this. config( "vodAccessKeyId"),
secretAccessKey: this. config( "vodSecretAccessKey"),
endpoint: this. config( "vodEndpoint"),
apiVersion: this. config( "vodApiVersion")
});
var res = await client. request( 'GetVideoPlayAuth', { VideoId: VideoId, AuthInfoTimeout: 100 });
// this.logger.info('Aliyun-VOD GetVideoPlayAuth:%s', JSON.stringify(res));
console. log( 'Aliyun-VOD GetVideoPlayAuth:%s', JSON. stringify( res));
this. json({ 'errno': 0, 'data': res});
} else {
this. json({ 'errno': 1, 'errmsg': "视频id不存在"});
}
}

        页面

    < link rel= "stylesheet" href= "//g.alicdn.com/de/prismplayer/2.7.1/skins/default/aliplayer-min.css" />
    < script type= "text/javascript" src= "//g.alicdn.com/de/prismplayer/2.7.1/aliplayer-min.js"></ script>
    
    容器
    < div class= "prism-player" id= "J_prismPlayer" style= "display: none;width:100%; height:200px;"></ div>
    
    实例化

    var player ;
    var vid = "c4d4915538dc4528a7f6c676d06ed08b" // 视频id
    var isLimited = true ; // 当前用户观看时长是否受限
    var limitTimeLen = 180 ; // 受限时长,单位秒
    var int ;
 

        


    
$ ( function (){
     $ . post ( "/openapi/video/getvideoplayauth" ,{vid: vid }, function (res){
         if ( res . errno == 0 ){
             var obj = res .data;
             player = new Aliplayer ({
                id: 'J_prismPlayer' ,
                width: '100%' ,
                autoplay: false ,
                 //支持播放地址播放,此播放优先级最高
                 // source : '播放url',
                 //播放方式二:点播用户推荐
                vid: vid ,
                playauth: obj . PlayAuth ,
                cover: obj . VideoMeta . CoverURL , //'http://liveroom-img.oss-cn-qingdao.aliyuncs.com/logo.png',
                 //播放方式三:仅MPS用户使用
                 // vid : '1e067a2831b641db90d570b6480fbc40',
                 // accId: '',
                 // accSecret: '',
                 // stsToken: '',
                 // domainRegion: '',
                 // authInfo: '',
                 //播放方式四:使用STS方式播放
                 // vid : '1e067a2831b641db90d570b6480fbc40',
                 // accessKeyId: '',
                 // securityToken: '',
                 // accessKeySecret: ''
            }, function (player) {
                 //console.log('播放器创建好了。')
            });

            
             player . on ( "ended" , endedHandle );

             // player.on("completeSeek", test);
             if ( isLimited == true ){
                 initLimitCheck ();
            }

        } else {
             //alert(res.msg);
        }
    })
});

function endedHandle () {
var newPlayAuth = "" ;
$ . post ( "/openapi/video/getvideoplayauth" ,{vid: vid }, function (res){
console . log ( res )
if ( res . errno == 0 ){
var obj = res .data;
player . replayByVidAndPlayAuth ( vid , obj . PlayAuth );

} else {
alert ( res . msg );
}
})
}

function initLimitCheck () {
if ( player ) {
player . on ( "completeSeek" , checkLimitTime );
player . on ( "play" , checkLimitTime );

int = window. setInterval ( "checkLimitTime()" , 2000 );
}
}

function checkLimitTime (e) {
//console.log(e)
if ( player ) {
var curTime = 0 ;
if ( e && e .type == "completeSeek" ) {
curTime = parseFloat ( e . paramData );
//console.log("seek", curTime);
} else {
if ( player . getStatus () == 'playing' || player . getStatus () == 'loading' || player . getStatus () == 'play' || player . getStatus () == 'pause' ) {
curTime = player . getCurrentTime ();
// console.log("play", curTime);
}
}
if ( curTime >= limitTimeLen ) {
player . pause ();
alert ( "您还未购买该课程,请购买后观看剩余内容!" );
window. clearInterval ( int );
// player = null;
}
}
}

    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值