Playlist not working with dynamic Array
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?
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);
}
};
Thank you @ezequielalba so much! This fix worked perfectly!
anyone to write a PR for this fix ?
@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 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!
Большое спасибо, очень помогли