Remove multiple tracks from "Now playing"

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Degeim
Posts: 49
Joined: Fri Sep 02, 2011 3:34 am
Location: Trondheim, Norway

Remove multiple tracks from "Now playing"

Post by Degeim »

Hi there!

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);
}
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:

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.";
}
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?
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Remove multiple tracks from "Now playing"

Post by trixmoto »

This seems like the most logical way to remove all but one, as far as I can see. You might be able to minimise the jump by using this loop (in VBSCript)...

Code: Select all

      While SDB.Player.IsStartingPlayback
        SDB.ProcessMessages
      WEnd
You can use this after resetting the current song index, and it will let you update the current position as soon as the track is loaded.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Degeim
Posts: 49
Joined: Fri Sep 02, 2011 3:34 am
Location: Trondheim, Norway

Re: Remove multiple tracks from "Now playing"

Post by Degeim »

Alright, thanks. I think maybe the gap was reduced a tiny bit with that trick. ;)
Post Reply