Skip to content

Instantly share code, notes, and snippets.

@zengyun-hacker
Last active December 23, 2015 19:19
Show Gist options
  • Save zengyun-hacker/6681279 to your computer and use it in GitHub Desktop.
Save zengyun-hacker/6681279 to your computer and use it in GitHub Desktop.
/*
* attention: before this you should have a AVAudioPlayerDelegate
*/
//init
NSString *audioPath = [[NSBundle mainBundle]pathForResource:@"audio" ofType:@"mp3"];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
NSError *error;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&error];
if (error) {
DLog(@"fail to play audio!!!! error:%@",error.description);
return;
}
player.delegate = #your AVAudioPlayerDelegate#;
//play
[player play];
//pause
[player pause];
//stop
[player stop];
player.currentTime = 0;
@kylelk
Copy link

kylelk commented Sep 24, 2013

Is this objective-C? most people add a .m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment