View Issue Details

IDProjectCategoryView StatusLast Update
0019293MMW 5Extensions frameworkpublic2022-08-05 14:51
Reporterzvezdan Assigned To 
Status feedbackResolutionopen 
Summary0019293: tracklist.add method adds track in a strange sort order, instead as the last one
Descriptiontracklist.add method adds track in strange sort order. However, what is even more strange, sometimes that method gives tracklists with the correct order of tracks, but when the same tracklist is added to the playlist using addTracksAsync, the playlist has the same strange order.

It seems that tracklist.insert method doesn't have this problem, i.e. tracks are added in the specified order with oQueueLst.insert(oQueueLst.count, oSelTrack);.

playlist.addTrackAsync method correctly adds tracks to the end of playlist.
Steps To Reproduce1. install the test script;
2. create ZDTest playlist and make it visible;
3. open DevTools / Console;
4. add several tracks to the Playing list;
5. select the first track in Playing;
6. click on the script's toolbar button -> track is added to the playlist;
7. select remaining tracks from the Playing list;
8. click on the toolbar button -> tracks are added before the previously added one, so instead of e.g.: T1, T2, T3, T4 I am getting T2, T3, T4, T1.
Additional InformationHere is the content of init.js:
window.uitools.addToolButton('righttoolbuttons', 'remove', function () {
    app.playlists.getByTitleAsync('ZDTest').then(function(goQueueListPlaylist) {
        var oQueueLst = goQueueListPlaylist.getTracklist();
        oQueueLst.whenLoaded().then(function () {
            var selTracks = window.uitools.getSelectedTracklist();
            selTracks.whenLoaded().then(function () {
                var oSelTrack;
                oQueueLst.modifyAsync(function () {
                    selTracks.locked(function () {
                        for (var i = 0; i < selTracks.count; i++) {
                            oSelTrack = selTracks.getFastObject(i, oSelTrack);
                }).then(function () {
                    oQueueLst.locked(function () {
                        for (var i = 0; i < oQueueLst.count; i++) {
                            var oTrack = oQueueLst.getValue(i);
                            console.log('oQueueLst - i: ' + i + ', "' + oTrack.title + '"');
                    goQueueListPlaylist.clearTracksAsync().then(() => {
                        goQueueListPlaylist.addTracksAsync(oQueueLst).then(() => {
                            goQueueListPlaylist.getTracklist().whenLoaded().then((oPlsTracks) => {
                                oPlsTracks.locked(function () {
                                    for (var i = 0; i < oPlsTracks.count; i++) {
                                        var oTrack = oPlsTracks.getValue(i);
                                        console.log('oPlsTracks - i: ' + i + ', "' + oTrack.title + '"');
}, 'Test');
TagsNo tags attached.
Fixed in build



2022-07-26 18:42


Test3.mmip (796 bytes)


2022-08-05 13:10

developer   ~0068970

Last edited: 2022-08-05 13:12

I think that the problem here could be the getFastObject usage?
As noted there with getFastObject you shouldn't preserve this object for later use, because it would be modified and the result would be unexpected.

Can you try whether the same issue happens when you replace the loop:

selTracks.locked(function () {
                        for (var i = 0; i < selTracks.count; i++) {
                            oSelTrack = selTracks.getFastObject(i, oSelTrack);

just by this line:

oQueueLst.addList( selTracks );


Or alternativelly replace getFastObject() by getValue(), but addList is much faster.


2022-08-05 14:49

reporter   ~0068977

It has the same problem with getValue method instead of getFastObject.

We had the similar conversation before. This is just a test example that is maximally simplified to show you the problem. The actual code is a way more complex. I cannot use addList method or any of your forEach methods because the adding of tracks to the intermediary tracklist is executed in the actual script conditionally, and it has not just one if condition, but much more.

What is particularly strange with this whole thing is that sometimes the intermediary tracklist has the correct order, but when it is added to the playlist with the addTracksAsync method, that playlist will have the wrong order.


2022-08-05 14:51

reporter   ~0068978

Well, I don't have a problem since, as I said, the insert method works fine (with the getFastObject) instead of the add method. But I think you should fix this issue anyway.