在 iPhone 上使用 html5 视频事件,如何告诉“完成”简单的暂停点击按钮?

发布于 2024-09-07 00:00:07 字数 512 浏览 2 评论 0 原文

我有一个适用于 iPhone 的网页,它使用 HTML5 视频标签。在 iPhone 上,此类嵌入视频在本机播放器中播放。我想检查视频何时结束以及用户何时使用“完成”按钮关闭视频。最初,我尝试了这个:

var video = $("#someVideo").get(0);          
video.addEventListener('ended', myFunction);

但只有当视频被允许结束时才会触发。在尝试了其他事件(挂起、停止、等待)后,我发现“完成”按钮会触发“暂停”事件。但是,当我添加此内容时:

video.addEventListener('pause', myFunction);

当用户点击播放控件中的暂停按钮时,我的代码会从“完成”按钮调用。第二种情况是不可取的;我只想要第一个案例,但事件似乎没有给我足够的信息。

有谁知道如何判断用户何时点击 iPhone 播放器中的“完成”按钮(而不是简单地暂停)?

I've got a web page for the iPhone that uses the HTML5 video tags. On the iPhone, such embedded videos are played in the native player. I wanted to check when the video had ended and when the user had dismissed the video with the "Done" button. Initially, I tried this:

var video = $("#someVideo").get(0);          
video.addEventListener('ended', myFunction);

But that only fired when the video was allowed to finish. After some playing around with other events (suspend, stalled, waiting) I found that the "Done" button triggers a 'pause' event. However, when I add this:

video.addEventListener('pause', myFunction);

my code is called both from the "Done" button and when the user taps the pause button in the playback controls. The second case is undesirable; I only want the first case, but the events don't seem to be giving me enough information.

Does anyone know of a way to tell when the user has hit the "Done" button in the iPhone player (versus simply pausing)?

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

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

发布评论

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

评论(3

眼睛会笑 2024-09-14 00:00:07

只需检查暂停函数中的 webkitDisplayingFullscreen 布尔值即可。按“完成”或“暂停”会触发暂停事件,但“完成”的作用有点像退出全屏模式。进行该检查将帮助您区分两次按下的按钮。
下面是一些示例代码。

<script>
var html5Video = function() {
    return {
        init: function() {
            var video = document.getElementsByTagName('video')[0];
            video.addEventListener('ended', endVideo, false);
            video.addEventListener('pause', pauseVideo, false);
        }
    };
}();

function endVideo() { 
    alert("video ended");
}

function pauseVideo() { 
    var video = document.getElementsByTagName('video')[0];
    if (!video.webkitDisplayingFullscreen)
        endVideo(); 
}

html5Video.init();

</script>

Just check the webkitDisplayingFullscreen boolean in your pause function. Pressing Done or Pause triggers the pause event, but Done does a wee bit extra like an exit from full screen mode. Doing that check will help you differenciate the 2 button presses.
Some sample code below.

<script>
var html5Video = function() {
    return {
        init: function() {
            var video = document.getElementsByTagName('video')[0];
            video.addEventListener('ended', endVideo, false);
            video.addEventListener('pause', pauseVideo, false);
        }
    };
}();

function endVideo() { 
    alert("video ended");
}

function pauseVideo() { 
    var video = document.getElementsByTagName('video')[0];
    if (!video.webkitDisplayingFullscreen)
        endVideo(); 
}

html5Video.init();

</script>
画离情绘悲伤 2024-09-14 00:00:07

这就是您所需要的:

yourplayer.addEventListener('webkitendfullscreen', onPlayerExitFullscreen, false);

反之亦然

yourplayer.addEventListener('webkitbeginfullscreen', onPlayerEnterFullscreen, false);

这是我找到的您问题的另一个答案: 如何判断 HTML5 视频播放器何时在 iOS / iPad 上进入全屏模式?

This is what you need:

yourplayer.addEventListener('webkitendfullscreen', onPlayerExitFullscreen, false);

And vice versa

yourplayer.addEventListener('webkitbeginfullscreen', onPlayerEnterFullscreen, false);

Here's another answer to your question that I found: How to figure out when a HTML5 video player enters the full screen mode on iOS / iPads?

陈独秀 2024-09-14 00:00:07

有一个名为“结束”的事件,您可能应该使用它,请参阅 http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#event-media-ending

There is an event called "ended" that you should probably use, see http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#event-media-ended .

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