Skip to content

Instantly share code, notes, and snippets.

@yfujiki
Created January 23, 2012 16:20
Show Gist options
  • Save yfujiki/1664062 to your computer and use it in GitHub Desktop.
Save yfujiki/1664062 to your computer and use it in GitHub Desktop.
Play music in iPhone application
NSError * error;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
if(error)
NSLog(@"Failed to set category to the AVAudioSession : %@", [error localizedDescription]);
NSURL * musicURL = [[NSBundle mainBundle] URLForResource:@"music_file_name" withExtension:@"mp3"];
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:&error];
if(error)
NSLog(@"Failed to play AVAudioSession : %@", [error localizedDescription]);
[self.player play];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment