View Issue Details

IDProjectCategoryView StatusLast Update
0019300MediaMonkey 5Extensions frameworkpublic2022-09-16 22:03
Reporterzvezdan Assigned To 
PriorityurgentSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version5.0.3 
Target Version5.0.4Fixed in Version5.0.4 
Summary0019300: playlist/player.setTracklist() method needed
DescriptionThe suggested method should work similarly to the tracklist.useList method, but applied directly on the playlist or player objects, i.e. it should perform clearTracksAsync and addTracksAsync methods. The problem when using combination of these two existing methods is that:
1. it causes flickering of tracks in the playlist;
2. it could lead to the incorrect data since these methods are executed asynchronously, which means that some another part of code that use the same list could be executed between these two methods.

These problems happens even when these two methods are used between beginUpdate/endUpdate.
Steps To Reproduce1. add the attached add-on;
2. create 'ZDTest' playlist and add several tracks to it;
3. open DevTools / Console;
4. click on the add-on's toolbar button and wait -> you will see reported the number of tracks in the log that are different than the actual number of tracks in the playlist.
Additional InformationHere is the content of the init.js:
var goQueueListPlaylist;
var giTrackCount;

window.uitools.addToolButton('righttoolbuttons', 'remove', function () {
    var progress = app.backgroundTasks.createNew();
    app.playlists.getByTitleAsync('ZDTest').then(function(oCurPlaylist) {
        if (!oCurPlaylist) {
            ODS("ZDTest playlist doesn't exist");
            return;
        }
        goQueueListPlaylist = oCurPlaylist;
        (function loop() {
            setTimeout(function() {
                var oQueueList = oCurPlaylist.getTracklist();
                oQueueList.whenLoaded().then(function () {
                    giTrackCount = oQueueList.count;
                    goQueueListPlaylist.beginUpdate();
                    goQueueListPlaylist.clearTracksAsync().then(() => {
                        goQueueListPlaylist.addTracksAsync(oQueueList).then(() => {
                            goQueueListPlaylist.endUpdate();
                            if (!progress.terminated && !window._cleanUpCalled) {
                                loop();
                            }
                        });
                    });
                });
            }, 250);
        })();
        (function loop() {
            setTimeout(function() {
                var goQueueList = goQueueListPlaylist.getTracklist();
                goQueueList.whenLoaded().then(async () => {
                    if (goQueueList.count != giTrackCount) {
                        console.log('ZDTest6 - goQueueList.count: ' + goQueueList.count);
                    }
                    if (!progress.terminated && !window._cleanUpCalled) {
                        loop();
                    }
                });
            }, 250);
        })();
    });
}, 'ZDTest6');
TagsNo tags attached.
Fixed in build2663

Activities

zvezdan

2022-08-07 07:01

updater  

ZDTest6.mmip (818 bytes)

Ludek

2022-09-14 10:56

developer   ~0069253

Last edited: 2022-09-14 11:00

For the Playlist I introduced new function setTracksAsync (that is combination of clearTracksAsync and addTracksAsync as suggested) in build 5.0.4.2663
image.png (10,396 bytes)   
image.png (10,396 bytes)   

Ludek

2022-09-14 11:00

developer   ~0069254

For the Player I have found that addTracksAsync already have the 'withClear' param that can be used to clear the Playing queue at first, see: https://www.mediamonkey.com/docs/api/classes/Player.html

peke

2022-09-16 22:03

developer   ~0069340

Verified 2662

API DOC page is at https://www.mediamonkey.com/docs/api/classes/Playlist.html#method_setTracksAsync