このコードを使用して多くのocメソッドが述べられていることがわかりました
******** メタデータは AVMetadataItem クラスです
NSString *path =[ [NSBundle mainBundle] pathForResource:@"musicname" ofType:@"mp3"];
NSURL *fileURL = [NSURL fileURLWithPath:path];
AVURLAsset *avURLAsset = [[AVURLAsset alloc] initWithURL:fileURL options:nil];
for (NSSting *format in [avURLAsset availableMetadataFormats]){
for (AVMetadataItem *metadata in [avURLAsset metadataForFormat:format]){
if([metadata.commonKey isEqualToString:@"title"]){
NSSting *title = (NSSting *)metadata.value;
}
if([metadata.commonKey isEqualToString:@"artwork"]){
UIImage *coverImage = [UIImage imageWithData:[(NSDictionary *)metadata.value objectForKey:@"data"]];
}
}
}
私はプログラミングにswiftを使用しているので、このようにswiftでそれをやろうとしています
func getArtworkForTrack(trackNumber: Int) -> NSData {
let asset = trackAVURLAssets[trackNumber]
var artworkData: NSData = NSData()
for metadata in asset.metadata {
if let commonKey = metadata.commonKey {
if commonKey == "artwork" {
if let keySpace = metadata.keySpace {
if keySpace == AVMetadataKeySpaceiTunes {
print("keyspace == AVMetadataKeySpaceiTunes")
artworkData = (metadata.value?.copyWithZone(nil))! as! NSData
} else {
let dic = metadata.value as! NSDictionary
let image = UIImage(data: dic.objectForKey("data") as! NSData)
}
}
}
}
}
return artworkData
}
しかし、実行すると、実行時エラーが発生します。
Could not cast value of type '__NSCFData' (0xbdbe94) to 'NSDictionary' (0xbdc394).
(lldb)
この行で:
let dic = metadata.value as! NSDictionary
問題THXを解決する方法を教えてください!