Get iTunes Artwork for Current Song with ScriptingBridge

六眼飞鱼酱① 提交于 2019-12-03 13:47:32

Ok so I figured it out. The solution is to use the NSData raw data provided by the API rather than the NSImage. So I used:

NSImage *songArtwork = [[NSImage alloc] initWithData:[artwork rawData]];

rather than

songArtwork = [artwork data];

I have to fetch batch of track artworks from iTunes and use ‘rawData’ too. But this way is inefficient. I found a better way (actually it decreases ‘fetch’ time about 2 times, it’s very significant when fetching artworks for many tracks using ‘valueForKey:’ according to «Improving the Performance of Scripting Bridge Code»).

So I decided to understand what’s wrong with iTunesArtwork ‘data’ property. We expect to get an NSImage object (according to iTunes.h ), but real object is kind of ‘NSAppleEventDescriptor’. And it’s easy to guess, that this object contains an image for us. So we can just use ‘data’ property to get image data. And this is really faster than getting ‘rawData’ from iTunesArtwork. But sometimes iTunes return NSImage object instead NSAppleEventDescriptor. This is an strange behavior, but it's still faster then using rawData.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!