Translate

2013年3月7日 星期四

AVAudioPlayer play mp3 and replay

use
AVAudioPlayer need add AVFoundation.framework!

and
 #import <AVFoundation/AVFoundation.h>
AVAudioPlayer Notification issue: delegate- audioPlayerDidFinishPlaying:successfully

AVAudioPlayer *player;

播放mp3



NSString *fileName = @"test"; NSURL *url = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"] isDirectory:NO]; NSError* error = nil; player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; player.delegate = self; if (!url || error) { } player.volume = 1; player.numberOfLoops = -1;// -1 = repeat forever [player prepareToPlay]; [player play]; pause if([player isPlaying]) { [player pause]; player = nil; } #pragma mark - #pragma mark AVAudioPlayer delegate - (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *)aPlayer successfully: (BOOL)flag { if (flag == YES) { NSLog(@"audioPlayerDidFinishPlaying"); } }

沒有留言:

張貼留言