开发者

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

开发者 https://www.devze.com 2023-02-09 16: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 r

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 re开发者_如何学运维wind to show the first frame as it does now.

Is it possible to change this behaviour?


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


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!


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号