track.loadCoverListAsync() not working properly

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: track.loadCoverListAsync() not working properly

Re: track.loadCoverListAsync() not working properly

by bdshasta » Sun Jun 05, 2022 10:42 pm

That worked, problem solved, thank you!

Re: track.loadCoverListAsync() not working properly

by drakinite » Thu Jun 02, 2022 10:28 pm

1 - track.loadCoverListAsync() is actually poorly named. It does not return a promise; instead, it returns the CoverList immediately. So when you're awaiting track.loadCoverListAsync(), the await does nothing. (If you await a non-Promise variable, it'll just return that variable instantly.)
2 - list.count only becomes valid after you await list.whenLoaded(). If you do not wait until it is loaded, sometimes the count will be zero and sometimes it will be correct (or even perhaps a number in between 0 and the correct value).
3 - covers.locked(), covers.getValue, and exportCover.saveToFile() are all synchronous. Do not await them (same reason as #1).


Should look something akin to this:

Code: Select all

        saveCoverToFile: async function(track, path){
            // exports first cover of track
            var _this = this;
            var covers = track.loadCoverListAsync();
            await covers.whenLoaded();
            console.debug(`covers.count= ${covers.count}`);
    
            if(covers.count > 0){
                covers.locked(async () =>{
                    var exportCover = covers.getValue(0);
                    var ext = await _this.getCoverFileType(exportCover.pictureType);
                    var exportPath = `${path}\.${ext}`;
                    exportCover.saveToFile(exportPath);
                });
            }
        },

If you prefer one-liners, the following snippet is also valid (because you're awaiting the promise that whenLoaded() returns, not the list returned by loadCoverListAsync()):

Code: Select all

var covers = await track.loadCoverListAsync().whenLoaded();

track.loadCoverListAsync() not working properly

by bdshasta » Tue May 31, 2022 3:40 pm

Please consider the following code snippet. I have this piece of code to grab the first track's cover art and save to a file. Outside of this code I have same being performed for other track metadata. The other track metadata *always* works. The below snippet works always when I manually select a new track and play it, but it only works around 5% of the time when the track switches in a playlist. Again, the non-cover art metadata always fires properly in both manual plays and playlists.

I've narrowed it down to var covers = await track.loadCoverListAsync() not actually returning >0 for tracks when they are part of a playlist. Then again, 5% of the time they do return >0. And again they return >0 100% of the time when I play those same tracks manually.

Any idea where to debug this next?

Code: Select all

	
	saveCoverToFile: async function(track, path){
		// exports first cover of track
		var _this = this;
		var covers = await track.loadCoverListAsync()
		console.debug(`covers.count= ${covers.count}`);

		if(covers.count > 0){
			await covers.whenLoaded(await covers.locked(async () =>{
				var exportCover = await covers.getValue(0);
				var ext = await _this.getCoverFileType(exportCover.pictureType);
				var exportPath = `${path}\.${ext}`;
				await exportCover.saveToFile(exportPath);
			}))
		}
	},

Top