Reading ID3 tags from an audio file.

Joined
May 8, 2009
Messages
6
Reaction score
0
Points
1
We allow customers in our application to select their own mp3 to put with an "order". When they do I need to be able to read the length of the song in seconds.

I have tried the AudioToolbox and QTKit unsuccessfully. I am not an extremely experienced objective-c, but can get around a little.

Thank you very much for your help.

Code:
-(IBAction)AddMusicFile:(id)sender
{
	int iResponse = NSRunAlertPanel(@"Add Song", 
					@"By clicking yes, you confirm that you have purchased the song(s) you are uploading and have the rights to use the music for the intended purpose.",
					@"Yes", @"No", /*ThirdButtonHere:*/nil
					/*, args for a printf-style msg go here */);
	switch(iResponse) {
		case NSAlertDefaultReturn:    /* user pressed OK */
			break;
		case NSAlertAlternateReturn:  /* user pressed Cancel */
			return;
			break;
		case NSAlertOtherReturn:      /* user pressed the third button */
			return;
			break;
		case NSAlertErrorReturn:      /* an error occurred */
			return;
			break;
	}
	
	Package *order = CurrentPackage;
	NSString * songName = [self AddMusicFileToOrder:order.PackageNumber];
	
	if (songName != nil)
	{
		SlideShowSong * showSong = [SlideShowSong new];
		showSong.MusicName = songName;
		showSong.CustomerUploaded = TRUE;
	
		NSInteger val = 0;
		for(SlideShowSong * song in [SelectedMusicInfoController content])
			if (song.Ordinal > val)
				val  = song.Ordinal;
		
		//RIGHT HERE I HAVE TO READ IN THE ID3 TAGS AND DETERMINE TOTAL LENGTH OF THE SONG IN SECONDS.
	
		showSong.Ordinal = val + 1;
		
		for(SlideShowSong * song in [SelectedMusicInfoController content])
		{
			if ([song.MusicName isEqualToString:showSong.MusicName])
				return;
		}
		
		[SelectedMusicInfoController addObject:showSong];
	}
	
}
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top