View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0019293 | MMW 5 | Extensions framework | public | 2022-07-26 18:42 | 2022-08-05 14:51 |
Reporter | zvezdan | Assigned To | |||
Priority | none | Severity | minor | Reproducibility | always |
Status | feedback | Resolution | open | ||
Summary | 0019293: tracklist.add method adds track in a strange sort order, instead as the last one | ||||
Description | tracklist.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 Reproduce | 1. 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 Information | Here 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); oQueueLst.add(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'); | ||||
Tags | No tags attached. | ||||
Attached Files | |||||
Fixed in build | |||||
|
I think that the problem here could be the getFastObject usage? See https://www.mediamonkey.com/docs/api/classes/SharedList.html#method_getFastObject 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); oQueueLst.add(oSelTrack); } }); just by this line: oQueueLst.addList( selTracks ); ? Or alternativelly replace getFastObject() by getValue(), but addList is much faster. |
|
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. |
|
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. |