Html 在 iPhone 上使用 html5 视频事件,如何通过简单的暂停判断“完成”按钮的点击?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3097545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:34:01  来源:igfitidea点击:

Using html5 video events on the iPhone, how do I tell "Done" button click from a simple pause?

iphonevideohtml

提问by jak

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 andwhen the user had dismissed the video with the "Done" button. Initially, I tried this:

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

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 andwhen 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)?

有没有人知道一种方法来判断用户何时点击了 iPhone 播放器中的“完成”按钮(而不是简单地暂停)?

回答by Arv - ToolTwist

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.

只需检查暂停功能中的 webkitDisplayingFullscreen 布尔值即可。按 Done 或 Pause 会触发暂停事件,但 Done 会做一些额外的工作,就像退出全屏模式一样。进行该检查将帮助您区分 2 次按钮按下。下面的一些示例代码。

<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>

回答by Rex

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?

这是我发现的对您的问题的另一个答案:如何确定 HTML5 视频播放器何时在 iOS / iPad 上进入全屏模式?

回答by Silvia

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.

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