JS~jwPlayer为js预留的回调方法大总结

对于一个成功的产品,它是对外封闭的,但又是对外开放的,这句话并不矛盾,让我来说一下,说它对外封闭是因为它本身的代码不允许你去修改,而说它开放,是因为它为我们定义了很多API,或者叫回调方法,对于jwplayer来说,它为我们提供了很多js的回调方法(事件),它被包含在events属性上的.

应用场合

播放时记录当前视频的时间,播放完成时写入完成的时间,像这些功能,我们都可以通过事件回调的方法解决,即为events属性赋相应的值.

注意

测试时,jwplayer需要在正式网站上测试,而本地打开时,它的events属性是不启作用的

events 实例

 var player = jwplayer("mediaplayer").setup({
flashplayer: "player.swf",
file: 'http://localhost/222.mp4',
autostart: "true",
bufferlength: '20',
width: '400',
height: '400',
image: '111.jpg',
events: {
onComplete: function () { console.log("播放结束!!!"); },
onVolume: function () { console.log("声音大小改变!!!"); },
onReady: function () { console.log("准备就绪!!!"); },
onPlay: function () { console.log("开始播放!!!"); },
onPause: function () { console.log("暂停!!!"); },
onBufferChange: function () { console.log("缓冲改变!!!"); },
onBufferFull: function () { console.log("视频缓冲完成!!!"); },
onError: function (obj) { console.log("播放器出错!!!" + obj.message); },
onFullscreen: function (obj) { if (obj.fullscreen) { console.log("全屏"); } else { console.log("非全屏"); } },
onMute: function (obj) { console.log("静音/取消静音") }
}
});

其它回调方法

 player.onBufferChange(function () { alert("缓冲改变!!!"); });
player.onBufferFull(function () { alert("视频缓冲完成!!!"); });
player.onError(function (obj) { alert("播放器出错!!!" + obj.message); })
player.onFullscreen(function (obj) {
if (obj.fullscreen) { alert("全屏"); }
else { alert("非全屏"); }
});
player.onMute(function (obj) { }) // obj. mute是否静音
player.onPlaylist(function (obj) { //视频列表载入完成
alert(obj.playlist[0]['file']);
});
var callback = function () { alert("callback");};//定义一个回调方法
player.onPlaylistItem(callback) // 开始播放一个视频时触发obj.index为视频索引
player.onReady(callback) //准备就绪
player.onResize(callback) //obj.width obj.height 宽高
//进入播放时触发obj.oldstate 值:从BUFFERING PAUSE状态进入播放状态
player.onPlay(callback)
//进入暂停obj.oldstate 值1:从PLAYING BUFFERING状态进入暂停
player.onPause(callback)
player.onBuffer(callback) //进入加载obj.oldstate 值PLAYING, PAUSED or IDLE
player.onIdle(callback) //进入空闲obj.oldstate 值PLAYING, PAUSED or BUFFERING.
player.onComplete(callback) //结束播放
player.onVolume(callback) //obj.volume
player.onPlay(function () {
console.log(this.getPosition());
});

技巧

我们看到上面的player是它当前的jwplayer对象,有了这个对象,我们就可以在程序的其它位置调用jwplayer的相关回调方法了,如果你没有定义player对象,也可以通过索引

的方式去访问jwplayer实例,如jwplayer(0)表示第一个jwplayer对象.

相关截图

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKcAAAB/CAIAAAAFGUX5AAAJSUlEQVR4nO2dMZLlKBKGuYWOIUOH0ClwuIPusOngrrV4Y42TxnACzRGI2CBiD0CfgjVSoATpdU3161JHNPlZXSpJpdZPAlL+SlQWxkPdbYxa2xS8w3j9XQp+nk16cTp+VERrwHc7eNh8oKOTmdebPyB8PVX1uKjJhxRCiGg38Clnq/VVFatXh25SB/bSMhDxOCM6H4KZ5yJzzjlqvYWiOoBLIexoF23Z+Rd+zmsj63YQfoAz1kkkRDTzuoGZlFq0XpRSaqqypeAd7gAu5+zBdPJQU9BaK6Wm2ezofEgpnJp7gJhzRKf1So1mmufviyqqfwVNDx/RAWzzbGLO1M+3O8d1NinniHae57ve25QuQM3zrBgWY0RblF73kCjWqTvZEauuovoDNKojOgDHxaOopZse8bjZHsyq9dq3CeotUmYxDbB1CnmAPezrPCk1ab1axEWpVes6G2AD/3HWrvFddhA+De/hrdabD4k0u4v1oxunKK+xW0dl1lwmH5KHrVOdze+SmadyHsdVFNUf4FA9oq3j922sV40tRtph0TYFv4GPaEnaMuoD4p5ztlpj+RX9kYX1/NNsXPlDvGWUNleJ0A4llx2ET3PGep2xd7HOp2N1ylbho7sD2MNOY4QB0NpSg6hDA+NlrAsPUFU/n5471R0AV50GYGoiFOvtr1KZ4dPQfqpeewullMV901uZLnDVk5mnblC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LPgKuqOzBdoVlR/QGq6u+vqHxWop3m1SF2q7Pns1RcF+vn+utZ6s09wtnDv7+icqkidyzyuSMmttGDoWKjSk0Am1KKytItUmXwcZoaVBTfP7qi8ilwOeeO6C7ly3KN9dunAKky+AD98/obKyqfqpdC0sdk/goNIvLw9qs411+vQ/KPrqh89vxsbr+vd4/7Vq8+7HeFJaXK4BM0sf7Oisr8JLXwaP3RYuTP6+XArqEIDyFvZEdEVB8RUX1ERPUREd/ciEisj4ioPiKi+oiI6iMiqo+IqD4iovqIiOoj8n8xmt8dshN4SQAAAABJRU5ErkJggg==" alt="" />

上一篇:vs2010设置断点进行调试时不起作用


下一篇:(Problem 13)Large sum