我每次播放全屏时都需要检查(或者从全屏播出),换句话说,我需要在全屏方法触发时收听自定义事件,以便我可以在下面做其他事情。
答案 0 :(得分:6)
在初始化MediaElement之前,您需要添加这段代码:
MediaElementPlayer.prototype.enterFullScreen_org = MediaElementPlayer.prototype.enterFullScreen;
MediaElementPlayer.prototype.enterFullScreen = function() {
// Your code here
this.enterFullScreen_org();
}
MediaElementPlayer.prototype.exitFullScreen_org = MediaElementPlayer.prototype.exitFullScreen;
MediaElementPlayer.prototype.exitFullScreen = function() {
// Your code here
this.exitFullScreen_org();
}
答案 1 :(得分:0)
我也试图找到解决这个问题的方法。我的解决方案是观察Mediaelement播放器对象的isFullScreen
属性以进行更改。
示例代码:
...
var mejsFullScreen;
new MediaElementPlayer('#video', {
pluginPath: 'lib/mediaelement/',
flashName: 'flashmediaelement.swf',
success: function(mediaElement, DOMElement, player) {
mejsFullScreen= mediaElement.isFullScreen;
setInterval(function() {
if (mediaElement.isFullScreen != mejsFullScreen) {
if (mediaElement.isFullScreen) {
// do something on enter fullScreen
mejsFullScreen = mediaElement.isFullScreen;
} else {
// do something on leave fullScreen
mejsFullScreen = mediaElement.isFullScreen;
}
}
}, 500);
}
});
答案 2 :(得分:0)
实际上,打开全屏模式时将调度"enteredfullscreen"
事件。但是,此事件不是在mediaElement
上调度,而是在player
上调度。
您可以在启动播放器后附加事件监听器:
var myPlayer = new MediaElementPlayer("#video", options);
myPlayer.container.addEventListener(
"enteredfullscreen",
// your callback function goes here
false
);
或使用success
回调函数(只需将player
添加为第三个参数):
var myPlayer = new MediaElementPlayer("#video", {
// your options
success: function(mediaElement, domObject, player) {
player.container.addEventListener("enteredfullscreen", yourCallbackFunction)
}
});