在 MediaElement.js 中的视频末尾停止而不是倒带

发布于 2024-10-16 14:52:55 字数 123 浏览 9 评论 0原文

我想知道如何在视频结束时停止 MediaElement.js 播放器。我想知道如何在视频结束时停止 mediaelement.js 播放器。我希望保留最后一帧,而不是像现在一样倒带显示第一帧。

是否可以改变这种行为?

I'm wondering how to stop the MediaElement.js player at the end of the video. I wondered how to stop the mediaelement.js player at the end of a video. I was hoping to hold on the last frame and not rewind to show the first frame as it does now.

Is it possible to change this behaviour?

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

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

发布评论

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

评论(5

苏别ゝ 2024-10-23 14:52:55

我为这个问题编写了一个修复程序,John 合并到了 2.10.2 版本中。
现在有一个选项“autoRewind”,您可以将其设置为 false 以防止播放器返回到开头。
事件监听器不会被添加,也不再需要删除它。

$('video').mediaelementplayer({
    autoRewind: false
});

I wrote a fix for this problem and John merged in version 2.10.2.
There is now an option "autoRewind" that you can set to false to prevent the player from going back to the beginning.
The eventlistener is not added and there is no more need to remove it.

$('video').mediaelementplayer({
    autoRewind: false
});
红ご颜醉 2024-10-23 14:52:55

我相信 元素的默认行为是返回到开头,因此您只需要通过侦听结束事件来覆盖它。

var player = $('#myvideo').mediaelementplayer();

player.media.addEventListener('ended', function(e) {
    player.media.setCurrentTime(player.media.duration);
}, false);

希望有帮助!

I believe that the default behavior of the <video> element is to go back to the beginning so you'd just need to override this by listening for the ended event.

var player = $('#myvideo').mediaelementplayer();

player.media.addEventListener('ended', function(e) {
    player.media.setCurrentTime(player.media.duration);
}, false);

Hope that helps!

好久不见√ 2024-10-23 14:52:55

也许最好的解决方案是不要害怕并从 mediaelement 源中删除“倒回到开始视频结束”处理程序。

如果您进入 mediaelement 的源代码并搜索“end”,您最终会发现,到达视频结尾后的倒带实际上是 mediaelement 故意完成的。

如果您想删除该功能,请随意从 mediaelement 源中删除“结束”事件的处理程序。这解决了这个问题的其他答案中提到的所有问题,包括最后一帧和第一帧之间的闪烁。

Probably the best solution is not to be afraid and remove the "rewind-to-start-on-video-end" handler from mediaelement source.

If you go into the source code for mediaelement and search for "ended", you'll eventually see, that rewinding after reaching end of the video is actually done deliberately by mediaelement.

If you want to remove that functionality feel free to just remove that handler for "ended" event from mediaelement source. That solves all the problems, including flickering between last and first frame, mentioned in some other answers to this question.

双手揣兜 2024-10-23 14:52:55

由于某种原因, John Dyer 的回答中的代码对我来说也不起作用。然而,我能够让这个版本工作......

var videoPlayer = new MediaElementPlayer('#homepage-player', {
    loop: false,
    features:[],
    enablePluginDebug: false,
    plugins: ['flash','silverlight'],
    pluginPath: '/js/mediaelement/',
    flashName: 'flashmediaelement.swf',
    silverlightName: 'silverlightmediaelement.xap',

    success: function (mediaElement, domObject) { 
        // add event listener
        mediaElement.addEventListener('ended', function(e) {
            mediaElement.pause();
            mediaElement.setCurrentTime(mediaElement.duration);
        }, false);
    },
    error: function () { 
    }

});

videoPlayer.play();

我遇到的唯一问题 - 这是非常令人沮丧的,是它在 Chrome 中的最后一个帧和第一个帧之间闪烁。否则,它在 Firefox 和 IE 中按预期工作......

The code in John Dyer's answer didn't really work for me either for some reason. I was however able to get this version working...

var videoPlayer = new MediaElementPlayer('#homepage-player', {
    loop: false,
    features:[],
    enablePluginDebug: false,
    plugins: ['flash','silverlight'],
    pluginPath: '/js/mediaelement/',
    flashName: 'flashmediaelement.swf',
    silverlightName: 'silverlightmediaelement.xap',

    success: function (mediaElement, domObject) { 
        // add event listener
        mediaElement.addEventListener('ended', function(e) {
            mediaElement.pause();
            mediaElement.setCurrentTime(mediaElement.duration);
        }, false);
    },
    error: function () { 
    }

});

videoPlayer.play();

The only problem I'm having - which is very frustrating, is it is flickering between the LAST and FIRST frames in Chrome. Otherwise, it works as expected in Firefox and IE...

安静被遗忘 2024-10-23 14:52:55

我在播放音频文件时遇到这个问题

问题出在播放中,当您暂停播放器时,文件将停止,但在恢复之前,您必须将播放器的当前时间减少任何值,在您的情况下,您可以将其减少一帧也许

在设置源、加载文件并暂停之后,然后

    myplayer.player.play();
    var currentTime = myplayer.player.getCurrentTime();
    myplayer.player.setCurrentTime(currentTime-0.1);
    myplayer.player.setCurrentRail();

This problem i faced when playing audio files

The problem is in the play, when you pause your player the file will stop but before resuming you have to decrease the current time of the player by any value in your case you may decrease it by a frame maybe

after setting your source ,loading your file and pausing, then

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