Created
January 15, 2016 12:36
-
-
Save alfonsodev/dc2b644e968ab927fd37 to your computer and use it in GitHub Desktop.
Play a sound file in ObjC
This file contains hidden or 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
| // from http://codewithchris.com/avaudioplayer-tutorial/ | |
| @interface ViewController () | |
| { | |
| AVAudioPlayer *_audioPlayer; | |
| } | |
| @end | |
| // Construct URL to sound file | |
| - (void)viewDidLoad | |
| { | |
| [super viewDidLoad]; | |
| // Construct URL to sound file | |
| NSString *path = [NSString stringWithFormat:@"%@/drum01.mp3", [[NSBundle mainBundle] resourcePath]]; | |
| NSURL *soundUrl = [NSURL fileURLWithPath:path]; | |
| // Create audio player object and initialize with URL to sound | |
| _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment