English 中文(简体)
Stopping instead of rewinding at the end of a video in 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?

问题回答

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




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签