工作中经常用到一些腾讯的或者优酷的视频,以下是调用视频接口的方法,注意线上才有效。
调用腾讯视频播放器APi
<!doctype html> <html> <head> <meta charset="utf-8"> <title>调用腾讯视频播放器APi</title> <script src="http://qzs.qq.com/tencentvideo_v1/js/tvp/tvp.player.js" charset="utf-8"></script> </head> <body> <div id="videoCon" class="video"></div> <script> var video = new tvp.VideoInfo(); video.setVid("w0605len8by");//视频vid var player = new tvp.Player(750, 450);//视频高宽 player.setCurVideo(video); player.addParam("autoplay","0");//是否自动播放,1为自动播放,0为不自动播放 player.addParam("wmode","opaque"); player.addParam("showend",0); player.addParam("adplay",0); player.addParam("wmode","transparent"); player.addParam("pic","http://ossweb-img.qq.com/images/roco/act/a20120925movie/video_pic.jpg");//默认图片地址 player.addParam("flashskin", "http://imgcache.qq.com/minivideo_v1/vd/res/skins/TencentPlayerMiniSkin.swf");//是否调用精简皮肤,不使用则删掉此行代码 player.write("videoCon"); </script> </body>
调用优酷视频播放器APi
<script src="http://player.youku.com/jsapi" charset="utf-8"></script>
player =newYKU.Player('youkuplayer',{ styleid:'0', //播放样式0-9 client_id: '', //登录优酷在后台创建一个应用结可以拿到 vid: 'ID', //视频ID 跟腾讯的vid是一样的道理 autoplay:true, //是否自动播放视频 show_related:true, //播放完成是否显示相关视频 embsig: '', //嵌入式播放器签名(非网站类应用必须设置) password: 'md5('播放密码'+client_id)',//免密码播放 events:{ onPlayerReady:function(){/*your code*/},//播放器准备就绪调用 onPlayStart:function(){/*your code*/},//播放器开始播放时调用 onPlayEnd:function(){/*your code*/}//播放器结束播放时调用 player.create({ onpause:function(){ console.log('暂停了') }, onallended:function(){ console.log('播放完了') }, onfullscreen:function(){ if (this.isFullScreen == true) { console.log("全屏了") }else { console.log("取消全屏了") } } }) functionplayVideo(){ player.playVideo();//播放 } functionpauseVideo(){ player.pauseVideo();//暂停 } functionseekTo(s){ player.seekTo(s);//定位至指定时间 } functioncurrentTime(){ returnplayer.currentTime();//当前播放时间 }
文章评论(0)