aneuryzm
aneuryzm

Reputation: 64834

Cocoa: getting information and playing a mp3

What's the easiest way to:

  1. load an mp3 from filesystem
  2. get a mp3 bitrate metadata
  3. mp3 file size
  4. play the mp3 on iTunes

with Cocoa ?

I currently have the file path only.

Thanks

Upvotes: 1

Views: 589

Answers (1)

Parag Bafna
Parag Bafna

Reputation: 22930

For metadata you can use MDItem.

MDItem is a CF-compliant object that represents a file and the metadata associated with the file.

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

For file size

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

play the mp3 on iTunes

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

Upvotes: 1

Related Questions