mediaelement-plugins icon indicating copy to clipboard operation
mediaelement-plugins copied to clipboard

Playlist not working with dynamic Array

Open ezequielalba opened this issue 7 years ago • 6 comments

I am setting a player with a playlist dynamically, and the code will be something like this:

var playerInstance = $('audio').mediaelementplayer({
                    isVideo: false,
                    showPlaylist: false,
                    playlist: [
                         {
                          src: 'somestringsource',
                          title: 'sometitle'
                          },
                          {
                          src: 'somestringsource',
                          title: 'sometitle'
                          },
                          {
                          src: 'somestringsource',
                          title: 'sometitle'
                          }
                    ],
                    autoplay: true,
                    features: [
                        'prevtrack',
                        'playpause',
                        'nexttrack',
                        'current',
                        'progress',
                        'duration',
                        'volume',
                        'playlist']
});

The source strings are URLs pointed to an API that streams the song online.

The playlist loads correctly. Good.

But I have an issue, when the song ends when it tries to get the next in line triggers an error saying that the source doesn't exist?

If I click on the Next button it works perfectly.

Any ideas?

ezequielalba avatar Aug 22 '18 22:08 ezequielalba

Fix it by doing a hot-fix in this line: player.setSrc(player.playlist[++player.currentPlaylistItem]);

inside the playlist.js It was getting the object for each key, instead of the source for each key inside my array. did this:

player.endedCallback = function () {
                        if (player.currentPlaylistItem < player.listItems.length) {
                            var sourceObject = {};
                            sourceObject = player.playlist[++player.currentPlaylistItem];
                            player.setSrc(sourceObject.src);
                            player.load();
                            setTimeout(function () {
                                player.play();
                            }, 200);
                        }
                    };

ezequielalba avatar Aug 22 '18 22:08 ezequielalba

Thank you @ezequielalba so much! This fix worked perfectly!

Jokez80 avatar Sep 19 '18 15:09 Jokez80

anyone to write a PR for this fix ?

karawitan avatar Jul 09 '19 19:07 karawitan

@berryamin The repo is no longer maintained if you see there are a bunch of PRs open waiting for feedback or merges. I think that the way is to hot-fix on your own repo/local dev.

ezequielalba avatar Jul 12 '19 18:07 ezequielalba

@ezequielalba Any volonteer to take over maintainer role for mediaelement-plugins? John Dyer is open to new maintainer, if someone is volunteer, please let me know and ask John Dyer to grant you access. If no one volunteers, I might take the role. But I took mediaelement already, so dedicated maitainer for plugins would be great!

karawitan avatar Jul 13 '19 05:07 karawitan

Большое спасибо, очень помогли

SergeyPerelomov avatar Oct 30 '19 09:10 SergeyPerelomov