app.player.addTracksAsync track ordering issue [#18167]

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

MyVikes
Posts: 49
Joined: Sun Jul 02, 2017 1:20 am

app.player.addTracksAsync track ordering issue [#18167]

Post by MyVikes »

I'm having an issue I can't resolve with the addTrackAsync method in MM5. I'm able to add tracks but the order is always an alpha order on the TrackNumber versus the order of the tracks as specified in the query. You can see in the code below were i add an ORDER BY on the DiscNumber and the TrackNumber and looking at the asJSON they are indeed ordered correctly but when passed to the addTrackAsync method they're being reorder as if the TrackNumber was alpha. So the in the playlist the sequence becomes 1, 10, 11, 2, 3, etc.

Without the ORDER BY I will see the tracks sorted as if the TrackNumber was alpha but with the ORDER BY they are definitely sorted by TrackNumber numerically.

This is being done in Javascript where previously this worked as intended using the COM objects in MM4 using newSongList = SDB.NewSongList and then SDB.Player.PlaylistAddTracks(newSongList ).

Code: Select all

let sql = "SELECT * FROM Songs WHERE IDAlbum = 12 ORDER BY CAST(DiscNumber as int), CAST(TrackNumber as int) ";

// also tried forcing the TrackNumber to have leading zeros in the ORDER BY (i.e. 1=001, 11=011, etc.)
//let sql = "SELECT printf('%03.0f', TrackNumber ) , * FROM Songs WHERE IDAlbum = 20 ORDER BY CAST(DiscNumber as int), printf('%03.0f', TrackNumber ) ";

console.log("selectAlbum sql:", sql);

var tracklist = app.db.getTracklist(sql, -1);

tracklist.whenLoaded().then(function () {
    console.log("selectAlbum tracklist count:" + tracklist.count);

    console.log("selectAlbum tracklist asJSON:", tracklist.asJSON);

    app.player.addTracksAsync(tracklist, {});
});
Any suggestion on how to control the sort order what adding to the playlist would be appreciated.
Ludek
Posts: 4245
Joined: Fri Mar 09, 2007 9:00 am

Re: app.player.addTracksAsync track ordering issue

Post by Ludek »

Hi, based on my tests it is the app.db.getTracklist() that does not respect the SQL order.

I used code:

Code: Select all

var tracklist = app.db.getTracklist("SELECT * FROM Songs WHERE PlayCounter > 0 ORDER BY SongTitle", -1);
        tracklist.whenLoaded().then(function () {
            console.log("tracklist count:" + tracklist.count);
            console.log("tracklist asJSON:", tracklist.asJSON);
            app.player.addTracksAsync(tracklist, {});
        });
... and even the tracklist.asJSON has already incorrect order (not by title).
app.player.addTracksAsync does not change the order further.

To be fixed as: https://www.ventismedia.com/mantis/view.php?id=18167

Thanks for reporting!
MyVikes
Posts: 49
Joined: Sun Jul 02, 2017 1:20 am

Re: app.player.addTracksAsync track ordering issue [#18167]

Post by MyVikes »

thx for the response
Post Reply