我有以下代码来检索currentTrack的作品(使用iTunes.h
):
iTunesArtwork *iTunesArtwork = [[iTunes.currentTrack artworks] objectAtIndex:0];
NSImage *artwork = iTunesArtwork.data;
if (artwork != nil){
[_musicImageView setImage:artwork];
}
它适用于大多数曲目但有时它会给我这个错误(即使曲目有图像):
NSImageCell's object value must be an NSImage.
2012-12-28 00:22:12.217 App[3256:303] (
0 CoreFoundation 0x00007fff904360a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8d5bf3f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff90435e7c +[NSException raise:format:] + 204
3 AppKit 0x00007fff9747c31b -[NSImageCell setObjectValue:] + 106
4 AppKit 0x00007fff974b8563 -[NSImageView setImage:] + 90
5 App 0x0000000100001b38 -[AppDelegate setupPlayer] + 600
6 Foundation 0x00007fff8d10c513 __NSFireTimer + 96
7 CoreFoundation 0x00007fff903f2da4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
8 CoreFoundation 0x00007fff903f28bd __CFRunLoopDoTimer + 557
9 CoreFoundation 0x00007fff903d8099 __CFRunLoopRun + 1513
10 CoreFoundation 0x00007fff903d76b2 CFRunLoopRunSpecific + 290
11 HIToolbox 0x00007fff939e40a4 RunCurrentEventLoopInMode + 209
12 HIToolbox 0x00007fff939e3e42 ReceiveNextEventCommon + 356
13 HIToolbox 0x00007fff939e3cd3 BlockUntilNextEventMatchingListInMode + 62
14 AppKit 0x00007fff97337613 _DPSNextEvent + 685
15 AppKit 0x00007fff97336ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
16 AppKit 0x00007fff9732e283 -[NSApplication run] + 517
17 AppKit 0x00007fff972d2cb6 NSApplicationMain + 869
18 App 0x0000000100001822 main + 34
19 libdyld.dylib 0x00007fff93cb77e1 start + 0
)
有关正在发生的事情的任何想法?
答案 0 :(得分:1)
确保它是一张图片 - 不仅仅是检查它是否为零,这还不够。 h文件中的类型不能是对象真正具有的类型。它更像是......它应该是一个图像:D
if([artwork isKindOfClass:[NSImage class]]) {
....
来自评论。 那并不总是奏效。埃尔。没有更多的崩溃,但有些图像没有显示。我们使用rawData作为后备:
//kind of like this
if(![artwork isKindOfClass:[NSImage class]]) {
artwork = [[NSImage alloc] initWithData:tunesArtwork.rawData];
}
if([artwork isKindOfClass:[NSImage class]]) {
...
}