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?