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;
在此行cell.detailTextLabel.text =問題[的NSString stringWithFormat:@ 「持續時間:%.2f秒」,sound.duration]; – AMH 2012-03-06 09:56:12
lblLabel2.text = [NSString stringWithFormat:@「%。2f」,sound.duration];我喜歡這樣做,它的工作 – Kartik 2012-03-06 10:03:28
仍然是相同的錯誤 – AMH 2012-03-06 10:28:10