objective-c – 使用ScriptingBridge获取当前歌曲的iTunes图稿

前端之家收集整理的这篇文章主要介绍了objective-c – 使用ScriptingBridge获取当前歌曲的iTunes图稿前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直试图弄清楚如何使用脚本桥获取当前正在播放的歌曲的iTunes艺术作品.我已经达到了适用于某些歌曲的程度,但对于其他歌曲,我得到了一个SIGABRT.我不确定问题是什么,所以任何帮助都将不胜感激.这是我到目前为止:
  1. iTunesApplication * iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
  2. NSImage *songArtwork;
  3. iTunesTrack *current = [iTunes currentTrack];
  4. iTunesArtwork *artwork = (iTunesArtwork *)[[[current artworks] get] lastObject];
  5. if(artwork != nil)
  6. songArtwork = [artwork data];
  7. else
  8. songArtwork = [NSImage imageNamed:@"Image.tiff"];
  9.  
  10. NSMenuItem *artworkMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
  11. [songArtwork setSize:NSMakeSize(128,128)];
  12. [artworkMenuItem setImage:songArtwork];
  13. [Menu insertItem:artworkMenuItem atIndex:0];

我可以使用一些歌曲,并在菜单项中很好地显示艺术作品,但对于其他人我在线上获得了一个SIGABRT:

  1. [songArtwork setSize:NSMakeSize(128,128)];

控制台的输出如下:

  1. 2011-08-12 23:13:20.094 SongViewer[2146:707] -[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70
  2. 2011-08-12 23:13:20.095 SongViewer[2146:707] An uncaught exception was raised
  3. 2011-08-12 23:13:20.096 SongViewer[2146:707] -[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70
  4. 2011-08-12 23:13:20.097 SongViewer[2146:707] (
  5. 0 CoreFoundation 0x00007fff86f11986 __exceptionPreprocess + 198
  6. 1 libobjc.A.dylib 0x00007fff8b04cd5e objc_exception_throw + 43
  7. 2 CoreFoundation 0x00007fff86f9d5ae -[NSObject doesNotRecognizeSelector:] + 190
  8. 3 CoreFoundation 0x00007fff86efe803 ___forwarding___ + 371
  9. 4 CoreFoundation 0x00007fff86efe618 _CF_forwarding_prep_0 + 232
  10. 5 SongViewer 0x0000000100002a83 -[IPMenulet awakeFromNib] + 4483
  11. 6 CoreFoundation 0x00007fff86f089e1 -[NSObject performSelector:] + 49
  12. 7 CoreFoundation 0x00007fff86f08962 -[NSSet makeObjectsPerformSelector:] + 274
  13. 8 AppKit 0x00007fff8d9d9c27 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
  14. 9 AppKit 0x00007fff8d9d01b9 loadNib + 322
  15. 10 AppKit 0x00007fff8d9cf6b6 +[NSBundle(NSNibLoading) _loadNibFile:naMetable:withZone:ownerBundle:] + 217
  16. 11 AppKit 0x00007fff8d9cf5d1 +[NSBundle(NSNibLoading) loadNibFile:externalNaMetable:withZone:] + 141
  17. 12 AppKit 0x00007fff8d9cf514 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
  18. 13 AppKit 0x00007fff8dc42355 NSApplicationMain + 398
  19. 14 SongViewer 0x0000000100001882 main + 34
  20. 15 SongViewer 0x0000000100001854 start + 52
  21. )
  22. 2011-08-12 23:13:20.098 SongViewer[2146:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',reason: '-[NSAppleEventDescriptor setSize:]: unrecognized selector sent to instance 0x102827f70'
  23. *** First throw call stack:
  24. (
  25. 0 CoreFoundation 0x00007fff86f11986 __exceptionPreprocess + 198
  26. 1 libobjc.A.dylib 0x00007fff8b04cd5e objc_exception_throw + 43
  27. 2 CoreFoundation 0x00007fff86f9d5ae -[NSObject doesNotRecognizeSelector:] + 190
  28. 3 CoreFoundation 0x00007fff86efe803 ___forwarding___ + 371
  29. 4 CoreFoundation 0x00007fff86efe618 _CF_forwarding_prep_0 + 232
  30. 5 SongViewer 0x0000000100002a83 -[IPMenulet awakeFromNib] + 4483
  31. 6 CoreFoundation 0x00007fff86f089e1 -[NSObject performSelector:] + 49
  32. 7 CoreFoundation 0x00007fff86f08962 -[NSSet makeObjectsPerformSelector:] + 274
  33. 8 AppKit 0x00007fff8d9d9c27 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
  34. 9 AppKit 0x00007fff8d9d01b9 loadNib + 322
  35. 10 AppKit 0x00007fff8d9cf6b6 +[NSBundle(NSNibLoading) _loadNibFile:naMetable:withZone:ownerBundle:] + 217
  36. 11 AppKit 0x00007fff8d9cf5d1 +[NSBundle(NSNibLoading) loadNibFile:externalNaMetable:withZone:] + 141
  37. 12 AppKit 0x00007fff8d9cf514 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
  38. 13 AppKit 0x00007fff8dc42355 NSApplicationMain + 398
  39. 14 SongViewer 0x0000000100001882 main + 34
  40. 15 SongViewer 0x0000000100001854 start + 52
  41. )
  42. terminate called throwing an exception(gdb)

如果有人知道可能出现什么问题,请告诉我!

解决方法

好的,我明白了.解决方案是使用API​​提供的NSData原始数据而不是NSImage.所以我用过:
  1. NSImage *songArtwork = [[NSImage alloc] initWithData:[artwork rawData]];

而不是

  1. songArtwork = [artwork data];

猜你在找的C&C++相关文章