Remove multiple tracks from "Now playing"
Posted: Wed Aug 07, 2013 5:02 pm
Hi there!
I want to remove multiple tracks from the "Now playing" playlist.
I realize that I can simply do the following:
This will delete them one by one, and does work. However, the list is refreshed in MediaMonkey for every single track, and it takes some time to delete a lot of tracks this way. I would like to delete them all in a single operation (without MediaMonkey having to refresh the list for each track), just like it is possible to add a lot of tracks at once by using PlaylistAddTracks().
My best working idea is the following:
This works, but there is a small jump in the playback (the track briefly restarts before my code brings it back to the place it was playing before). It is not critical, but certainly noticeable.
Is there any better way to quickly remove a lot of tracks from "Now playing" without interrupting the playback?
I want to remove multiple tracks from the "Now playing" playlist.
I realize that I can simply do the following:
Code: Select all
foreach (var i in indexes.Reverse())
{
list.Delete(i);
}
My best working idea is the following:
Code: Select all
internal string RemoveMultiple(IEnumerable<int> indexes)
{
var curr = _controller.SDBA.Player.CurrentSongIndex; //Remember current track ...
var pos = _controller.SDBA.Player.PlaybackTime; // ... and where we were in that track.
var list = _controller.SDBA.Player.CurrentPlaylist; //Save the list to a local variable
foreach (var i in indexes.Reverse())
{
list.Delete(i); //Delete tracks from the local list
if (i < curr) //Keep track of the index of the currently playing track
curr--;
}
//Here comes the ugly part ...
_controller.SDBA.Player.PlaylistClear(); //Clear out the playlist completely ...
_controller.SDBA.Player.PlaylistAddTracks(list); // ... and add the tracks that weren't deleted (adding multiple tracks is lightning fast)
//This works, but the currently playing song is not highlighted in the playlist anymore.
_controller.SDBA.Player.CurrentSongIndex = curr; //Hightlight it again. This will restart the track. :(
var start = DateTime.Now;
while (_controller.SDBA.Player.PlaybackTime != pos) //Jump back to where we were. Need to do this a couple of times for it to register.
{
_controller.SDBA.Player.PlaybackTime = pos; //Try once more!
if (DateTime.Now.Subtract(start).TotalMilliseconds > 500)
break; //Infinite loop failsafe
}
return "Removed " + indexes.Count() + " tracks from playlist.";
}
Is there any better way to quickly remove a lot of tracks from "Now playing" without interrupting the playback?