1,设定音量0.0~1.0
[myPlayer setVolume:0.5];
2,设定播放次数-1为无限循环
[myPlayer setNumberOfLoops:0];3,设定播放位置(重头播放)
[myPlayer setCurrentTime:0.0];4,播放
[myPlayer play];5,暂停
[myPlayer pause];6,停止
[myPlayer stop];7,音乐总长度
[myPlayer duration]
8,目前播放位置
[myPlayer currentTime]
9,声道数目
[myPlayer numberOfChannels]
10,向后跳转一秒
NSTimeInterval currentTime = [myPlayer currentTime];[myPlayer setCurrentTime:currentTime + 1];
-----------delegate,
1,- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag { NSLog(@"播放完毕");}
2,//电话中断- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)player { NSLog(@"被中断");}
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withOptions:(NSUInteger)flags { NSLog(@"从中断中恢复");}
3,取得播放档案的位置
NSURL* url = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"FileName" ofType:@"mp3"]];
4,与音乐档案做链接
NSError* error = nil;myPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];if (!url || error) { //错误处理程序}
5,档案存放于网络6,取得播放档案的位置 NSURL *url = [NSURL URLWithString:@"http://FileName.mp3"];NSData *myNetworkData = [NSData dataWithContentsOfURL:url];
7,与音乐档案做链接
NSError* error = nil;myPlayer = [[AVAudioPlayer alloc] initWithData:myNetworkData error:&error];if (!url || error) { //错误处理程序}
self.player = [self.player initWithContentsOfURL:[NSURL URLWithString:[VoiceRecorderBaseVC getPathByFileName:fileName ofType:@"wav"]] error:nil];
每次生成一遍,都进行了重新的初始化,
比如:self.player.isPlaying,
1,异步perform selector,
2,start,notend = playing,代理看是否播放完毕,