Stopping instead of rewinding at the end of a video in MediaElement.js

余生颓废 提交于 2020-01-03 14:13:23

问题


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?


回答1:


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
});



回答2:


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!




回答3:


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.




回答4:


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




回答5:


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();


来源:https://stackoverflow.com/questions/4962855/stopping-instead-of-rewinding-at-the-end-of-a-video-in-mediaelement-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!