MediaElement.js 知道播放器何时进入全屏

发布于 2025-01-05 11:11:52 字数 73 浏览 0 评论 0原文

我需要在每次播放器进入全屏(或从全屏退出)时进行检查,换句话说,我需要在触发全屏方法时监听自定义事件,以便我可以执行下面的其他操作。

i need check every time player goes fullscreen (or goes out from fullscreen), in other words, i need to listen to a custom event when the fullscreen method is triggered so i can do other things below.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

霞映澄塘 2025-01-12 11:11:52

在初始化 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();
}

You'll need to add this bit of code before initializing 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();
}
为你拒绝所有暧昧 2025-01-12 11:11:52

实际上,打开全屏模式时会调度一个“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)
    }
});

Actually, there is an "enteredfullscreen"event being dispatched when opening the fullscreen mode. However, this event is not being dispatched on the mediaElement, but on the player.

You can either attach the event listener after initiating the player:

var myPlayer = new MediaElementPlayer("#video", options);

myPlayer.container.addEventListener(
    "enteredfullscreen",
    // your callback function goes here
    false
);

or use the success callback function (just add the player as the third argument):

var myPlayer = new MediaElementPlayer("#video", {
    // your options
    success: function(mediaElement, domObject, player) {
        player.container.addEventListener("enteredfullscreen", yourCallbackFunction)
    }
});
愛上了 2025-01-12 11:11:52

我也试图找到解决这个问题的方法。我的解决方案是观察 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);
    }
});

I tried to find a solution to this problem as well. My solution is to watch the isFullScreen property of the Mediaelement player object for changes.

Sample code:

...
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);
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文