View Issue Details

IDProjectCategoryView StatusLast Update
0019294MediaMonkey 5Extensions frameworkpublic2022-08-07 05:48
Reporterzvezdan Assigned To 
PrioritynoneSeverityminorReproducibilityalways
Status feedbackResolutionreopened 
Summary0019294: Tracklist's adding/removal methods don't update tracks from the parent playlist/PlayingEntries
DescriptionIf I get a tracklist by e.g. playlist.getTracklist() or player.getSongList().getTracklist() and if I apply add, delete, remove or removeAsync methods to that tracklist, the parent object is not updated, i.e. the track is not added/removed from it.

playlist.removeSelectedTracksAsync() and app.player.removeSelectedTracksAsync() don't have this problem, but they complicate things because I need to store currently selected state of the playlist entries, then to select the track that I want to remove with setSelected(i, true), then execute the mentioned method and finally to restore back the selected state of the remaining tracks in the playlist/Playing list.
Steps To Reproduceremoval from Playing list:
1. put several tracks into Playing list;
2. open DevTools / Console;
3. execute any of the following lines in DevTools:
    a) var oPlayingTracks = app.player.getSongList().getTracklist(); oPlayingTracks.whenLoaded().then(() => {oPlayingTracks.modifyAsync(() => {oPlayingTracks.delete(0); app.player.getSongList().notifyChanged();});})
or
    b) var oPlayingTracks = app.player.getSongList().getTracklist(); oPlayingTracks.whenLoaded().then(() => {oPlayingTracks.modifyAsync(() => {oPlayingTracks.remove(oPlayingTracks.getValue(0)); app.player.getSongList().notifyChanged();});})
or
    c) var oPlayingTracks = app.player.getSongList().getTracklist(); oPlayingTracks.whenLoaded().then(() => {oPlayingTracks.modifyAsync(() => {oPlayingTracks.removeAsync(oPlayingTracks.getValue(0)).then(() => {app.player.getSongList().notifyChanged()});})})

removal from playlist:
1. create ZDTest playlist, make it visible and put several tracks to it;
2. open DevTools / Console;
3. execute any of the following lines in DevTools:
    a) app.playlists.getByTitleAsync('ZDTest').then((oPlaylist) => {var oPlaylistTracks = oPlaylist.getTracklist();
        oPlaylistTracks.whenLoaded().then(() => {oPlaylistTracks.modifyAsync(() => {oPlaylistTracks.delete(0); oPlaylist.notifyChanged()});})})
or
    b) app.playlists.getByTitleAsync('ZDTest').then((oPlaylist) => {var oPlaylistTracks = oPlaylist.getTracklist(); oPlaylistTracks.whenLoaded().then(() => {oPlaylistTracks.modifyAsync(() => {oPlaylistTracks.remove(oPlaylistTracks.getValue(0)); oPlaylist.notifyChanged()});})})
or
    c) app.playlists.getByTitleAsync('ZDTest').then((oPlaylist) => {var oPlaylistTracks = oPlaylist.getTracklist(); oPlaylistTracks.whenLoaded().then(() => {oPlaylistTracks.modifyAsync(() => {oPlaylistTracks.removeAsync(oPlaylistTracks.getValue(0)).then(() => {oPlaylist.notifyChanged()});})});})

adding to playlist:
1. put a track to Playling list;
2. create ZDTest playlist and make it visible;
3. select track in Playing list;
4. open DevTools / Console;
5. execute this line in DevTools:
var oSelTrack, selTracks = window.uitools.getSelectedTracklist(); selTracks.whenLoaded().then(function () {selTracks.locked(function () {oSelTrack = selTracks.getValue(0)})}); app.playlists.getByTitleAsync('ZDTest').then((oPlaylist) => {var oPlaylistTracks = oPlaylist.getTracklist(); oPlaylistTracks.whenLoaded().then(() => {oPlaylistTracks.modifyAsync(() => {oPlaylistTracks.add(oSelTrack); oPlaylist.notifyChanged()});})})

Nothing will be changed after these lines in the corresponding lists.
TagsNo tags attached.
Fixed in build

Relationships

related to 0019281 closedLudek "Incorrect interface type requested" error with PlaylistEntries.add method 

Activities

Ludek

2022-08-05 11:16

developer   ~0068969

Last edited: 2022-08-05 11:25

app.player.getSongList().getTracklist() returns just Tracklist built from the PlayerEntries list.

i.e. you need to operate directly the PlayerEntries to modify the list (this is related to our discussion in 0019281)

And for the Playlist you can use methods like removeTrackAsync, moveTrackAsync, removeSelectedTracksAsync ( https://www.mediamonkey.com/docs/api/classes/Playlist.html )

Alternativelly (for better performance) you can do all the necessary updates via SQL directly within the database and then call just playlist.notifyChanged('tracklist'); to update the tracklists of the affected playlist(s) -- or uitools.refreshView(); for mass operations.

zvezdan

2022-08-05 13:53

updater   ~0068975

I already mentioned why I would like to skip using removeSelectedTracksAsync() method.

Nothing is changed in my examples if I use playlist.notifyChanged() or player.notifyChanged() method. However, I suppose it is not possible to do it that way since the tracklist has not any connection with its parent after getting it with the getTracklist() method.

So, maybe you could add one new method to the playlist/player objects called setTracklist() or useList() or something like that.

zvezdan

2022-08-06 21:16

updater   ~0068991

I realized that my suggestion for adding setTracklist() method is for another issue and it cannot help in this case, because it has the same problem as the removeSelectedTracksAsync() method, i.e. it cannot keep the selected state of tracks, but it needs to be backed up and restored after removal.

What I would like is that you add a new playlist/player.removeTrackById method. The playlist object has removeTrackAsync() method, however the problem with it is that it removes all all instances of the same track from the playlist, but I need to remove just particular track, not its duplicates. The player method doesn't even have removeTrackAsync(), according to the API.

I also suggest that you consolidate all adding/removal methods between playlist and player objects.
Player missing:
- addTrackAsync
- addTrackById
- removeTrackAsync

Playlist missing:
- removeDuplicatesAsync
- removeNotAccessibleAsync

Should I open another issue with this request?

zvezdan

2022-08-07 05:48

updater   ~0068992

Sorry, I made a mistake again. I would like to have a playlist/player.removeTrackByIndex or deleteTrack method or something like that, not removeTrackbyId. It should work similarly to the tracklist.delete method, but applied directly to the playlist or player object.