音视频播放器JWPlayer使用方法总结
1,加载库文件
<script src="/assets/lib/jwplayer-7.12.0/jwplayer.js"></script>
<script>jwplayer.key='YOUR_KEY';</script>
2、HTML中初始化播放器
var option = {
file:"video_path", //单个片源播放 多个片源时用sources设置 sources:[{file:'',label:'',default:Boolean,type:''}]
width:Number/percentage
height:Numbmer,
image:image_path,
title:'',
description:'',
mute:Boolean,//是否静音
autostart: String, //是否自动播放
preload:
repeat:Boolean, //循环播放
aspectratio:'', //播放比例
playbackRateControls:Boolean/Array //播放倍率设置 true时展示默认0.5x,1.0x,1.25x,1.5x,2.0x false不展示,[1.0,2.0,4.0]定制设置
playlist:[{file:'',type:'',label:'',default:''}],//播放列表
}
var player = jwplayer("video").setup(option);
getPosition()获取当前时间点
getDuration()获取视频长度
getCurrentQuality()获取当前片源index
setCurrentQuality()设置当前片源index
getConfig()获取配置
getControls()获取控制条状态
getContainer()获取HTML区域
3、绑定事件on,off,once,triggle
player.on(event,function(){})
时间 回调函数返回值
play oldstate viewable
pause oldstate viewable
error message
seek position offset
time duration position viewable
seeked -
levelsChanged currentQuality({currentQuality:0,levels:[{label:''}])