Last active
December 23, 2015 19:19
-
-
Save zengyun-hacker/6681279 to your computer and use it in GitHub Desktop.
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
/* | |
* 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this objective-C? most people add a .m