2012-04-10 62 views
1

什么是最简单的方法:可可:获取信息和播放MP3

  1. 负荷从文件系统
  2. 一个mp3获得MP3文件比特率的元数据
  3. MP3文件大小
  4. 上播放iTunes中的MP3

with Cocoa?

我目前只有文件路径。

感谢

回答

1

对于您可以使用MDItem元数据。

MDItem是一个符合CF规范的对象,表示文件和与该文件关联的元数据 。

MDItemRef metadata = MDItemCreate(NULL, (CFStringRef)@"/Users/parag/0.mp3"); 
NSNumber *audioBitrate = (NSNumber *)MDItemCopyAttribute(metadata, kMDItemAudioBitRate); 
NSLog(@"audioBitrate:%i", [audioBitrate intValue]); 

对于文件大小

[[[NSFileManager defaultManager] attributesOfItemAtPath:@"/Users/parag/0.mp3" error:nil] fileSize]; 

播放iTunes上的MP3

NSString *cmd = @"open -a /Applications/iTunes.app '/Users/parag/0.mp3'"; 
system([cmd UTF8String]);