mediafront / osmplayer

The Open Standard Media Player is an all-in-one media player for the web. It is an industry changing, open source (MIT) media player that is built to dynamically deliver any type of web media, including HTML5, YouTube, Vimeo, and Flash.
http://www.mediafront.org
MIT License
342 stars 181 forks source link

How to avoid autoplay #58

Open skenklok opened 11 years ago

skenklok commented 11 years ago

Hi, i have a problem when i switch from one playlist(youtube) to another, i can't stop auto-play of new video. How to load the first element of the playlist without auto-play? can you help me please?

This is my code:

minplayer.get('media', function(media) { media.stop(); minplayer.get('playlist', function(playlist) { playlist.options.playlist = path; playlist.options.autoplay = false; playlist.load(0, 0); }) });

Thanks

Marco A.

travist commented 11 years ago

Yeah, this is done intentionally, so it may be hard to override. Here is the code that does this.

https://github.com/mediafront/osmplayer/blob/2.x/src/osmplayer.js#L137

What you may be able to do is hook into the event handler, and alter the data.autoplay before it makes it to this code. You can also force the options within the player which should handle the case if your event handler is called after the playlist load. Here is what I am thinking, but I have not yet tested it.

minplayer.get('player', function(player) {
  minplayer.get('playlist', function(playlist) {
    playlist.bind('nodeLoad', function(event, data) {
      data.autoplay = false;
      player.options.autoplay = false;
    });
  });
});
skenklok commented 11 years ago

HI thanks for your reply, my code load at the same time the playlist and the first element of it, so i'm not able to hook into the event handler before the loading. I've also try to stop the media but this intrudes every time i play any item. There's other similar solution or you've any others idea?

minplayer.get('playlist', function(playlist) {
                        playlist.options.playlist = path;
                        playlist.options.autoplay = false;
                        playlist.load(0, 0);
                        // Bind to the play event of the media.
                       media.bind('playing', {obj: this}, function(event) {
                           media.pause();
                        });
 });