app.player.addTracksAsync track ordering issue [#18167]
Posted: Sat Jul 24, 2021 8:39 am
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 ).
Any suggestion on how to control the sort order what adding to the playlist would be appreciated.
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, {});
});