Created
January 23, 2012 16:20
-
-
Save yfujiki/1664062 to your computer and use it in GitHub Desktop.
Play music in iPhone application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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