从m4a或wav解析标题?

时间:2012-11-15 14:10:58

标签: objective-c ios parsing wav m4a

如何从iOS(objective-c)上的wav或m4a文件轻松解析标题?

感谢您的解决方案。

1 个答案:

答案 0 :(得分:1)

NSBundle* bundle = [NSBundle mainBundle];
NSString* path = [bundle bundlePath];
NSURL * fileURL=[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/silence.mp3", path]];
AudioFileTypeID fileTypeHint = kAudioFileMP3Type;
NSString *fileExtension = [[fileURL path] pathExtension];
if ([fileExtension isEqual:@"mp3"]||[fileExtension isEqual:@"m4a"])
{
    AudioFileID fileID  = nil;
    OSStatus err        = noErr;

    NSDictionary *piDict = nil;
    UInt32 piDataSize   = sizeof( piDict );
    err = AudioFileGetProperty( fileID, kAudioFilePropertyInfoDictionary, &piDataSize, &piDict );
    if( err != noErr ) {
        [piDict release];
        NSLog( @"AudioFileGetProperty failed for property info dictionary" );
    }

    NSString * Album = [piDict objectForKey: 
                        [NSString stringWithUTF8String: kAFInfoDictionary_Album]];
    NSString * Artist = [piDict objectForKey: 
                         [NSString stringWithUTF8String: kAFInfoDictionary_Artist]];
    NSString * Title = [piDict objectForKey: 
                        [NSString stringWithUTF8String: kAFInfoDictionary_Title]];
    NSLog(@"%@",Title);
    NSLog(@"%@",Artist);
    NSLog(@"%@",Album);

}