PlayList.RemoveTrackNoConfirmation behavior?

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

Moderator: Gurus

PlayList.RemoveTrackNoConfirmation behavior?

Postby Just Guessing » Tue Sep 20, 2016 9:33 am

I have a playlist ("Test Playlist") and I want to remove a track (objSong) from it.

Experimenting with "RemoveTrackNoConfirmation" I find this will NOT work (unless certain challenging conditions are true):
Code: Select all
SDB.PlaylistByTitle("Test Playlist").RemoveTrackNoConfirmation objSong


it seems the argument for the method MUST be a playlist item, referenced as such. For example, this works:
Code: Select all
SDB.PlaylistByTitle("Test Playlist").RemoveTrackNoConfirmation  SDB.PlaylistByTitle("Test Playlist").Tracks.Item(0)


In fact, THIS WORKS (but removing track from the "Test Playlist" playlist only !!):
Code: Select all
SDB.PlaylistByTitle("A Completely Different Playlist").RemoveTrackNoConfirmation  SDB.PlaylistByTitle("Test Playlist").Tracks.Item(0)


Alright, a work around possibility (which will need a bunch of error avoidance code):
Code: Select all
for I = 0 To SDB.PlaylistByTitle("Test Playlist").Tracks.count - 1
   if objSong.ID = SDB.PlaylistByTitle("Test Playlist").Tracks.Item(i).ID Then match = i
next

SDB.PlaylistByTitle("Test Playlist").RemoveTrackNoConfirmation SDB.PlaylistByTitle("Test Playlist").Tracks.Item(match)


But... Am I missing something? This seems like very limited and/or buggy behavior.
Just Guessing
 
Posts: 64
Joined: Mon Sep 03, 2012 12:06 pm

Re: PlayList.RemoveTrackNoConfirmation behavior?

Postby Just Guessing » Tue Sep 20, 2016 3:13 pm

well, came up with a sub one can use, in case the SDB method behavior isn't as friendly as it could be (if this is needed)

so I'd use this:
PlaylistTrackRemove "Test Playlist", objSong

to call this:

Code: Select all
sub PlaylistTrackRemove(PlaylistName, SongObject)
   Dim i, ThePlaylist, TrackCount
   Set ThePlaylist = SDB.PlaylistByTitle(PlaylistName)
   TrackCount = ThePlaylist.Tracks.Count
   
   if ThePlaylist.id > 0 And Not SongObject Is Nothing Then
      if TrackCount > 0 Then
         for i = TrackCount - 1 To 0 Step -1
            if SongObject.ID = ThePlaylist.Tracks.Item(i).ID Then
               ThePlaylist.RemoveTrackNoConfirmation ThePlaylist.Tracks.Item(i)
            end if
         next
      end if
   end if
      
   SDB.MainTracksWindow.Refresh   
   Set ThePlaylist = Nothing
end sub
Just Guessing
 
Posts: 64
Joined: Mon Sep 03, 2012 12:06 pm

Re: PlayList.RemoveTrackNoConfirmation behavior?

Postby Peke » Wed Sep 21, 2016 9:12 pm

If I got you correctly you want to remove track by ID which is position in playlist?

I would suggest something like this:
Code: Select all
    sub PlaylistTrackRemove(PlaylistName, SongObject)
       Dim ThePlaylist, TrackCount
       Set ThePlaylist = SDB.PlaylistByTitle(PlaylistName).Tracks
       ThePlaylist.Delete(SongObject)
       ThePlaylist.UpdateAll
       SDB.MainTracksWindow.Refresh   
       Set ThePlaylist = Nothing
    end sub
Best regards,
Pavle
MM Core Developer and Admin of free MediaMonkey extensions Hosting
Image
Image
Peke
 
Posts: 10409
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia

Re: PlayList.RemoveTrackNoConfirmation behavior?

Postby Just Guessing » Thu Sep 22, 2016 5:27 pm

I get a type mismatch with that, unless I use "SongObject.ID".
But even though SongObject.ID gets no error, I don't find the track removed from the playlist.

example:
I want SDB.SelectedSongList.Item(0)
removed from playlist "Testing"

SDB.PlaylistByTitle("Testing").Tracks.Delete(SDB.SelectedSongList.Item(0).ID)

doesn't give error, but doesn't remove track from playlist... Nor does

SDB.PlaylistByTitle("Testing").RemoveTrackNoConfirmation( SDB.SelectedSongList.Item(0) )
Just Guessing
 
Posts: 64
Joined: Mon Sep 03, 2012 12:06 pm


Return to MediaMonkey 4 Addons developer forum

Who is online

Users browsing this forum: No registered users and 4 guests

cron