AudioFileID audioFile;
CFDictionaryRef piDict = nil;
UInt32 piDataSize = sizeof( piDict );
if (noErr != AudioFileOpenURL((CFURLRef)[NSURL fileURLWithPath:filePath], 0x01, kAudioFileCAFType, &audioFile))
{
return [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithString:filePath], @"FilePath", @"Unknown",@"Title",@"Unknown",@"Album",@"Unknown",@"Artist",@"0", @"Duration", nil];
}
if( noErr != AudioFileGetProperty( audioFile, kAudioFilePropertyInfoDictionary, &piDataSize, &piDict ))
{
AudioFileClose(audioFile);
return [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithString:filePath], @"FilePath", @"Unknown",@"Title",@"Unknown",@"Album",@"Unknown",@"Artist",@"0", @"Duration", nil];
}
AudioFileClose(audioFile);
if(piDict)
{
NSString * duration = @"0";
CFStringRef durationString = nil;
if ( piDict && CFDictionaryGetValueIfPresent(piDict, CFSTR(kAFInfoDictionary_ApproximateDurationInSeconds), (const void **) &durationString))
{
duration = (NSString*)durationString;
duration = [duration stringByReplacingOccurrencesOfString:@"," withString:@""];
}
if (duration)
[songInfomationDictionary setObject:duration forKey:@"Duration"];
CFRelease(piDict);
//get duration as string
}
return nil;