我有这段音频播放器代码,但我不知道为什么没有执行 audioPlayerDidFinishPlaying。
这是我的 audioplayer.m 文件中的部分代码
- (void)viewDidLoad {
[super viewDidLoad];
NSError* e = nil;
self.player = [[AVPlayer alloc] initWithURL:self.contentURL];
if(e)
{
NSLog(@"Detected error(%@)",e);
}
[self.playButton setImage:[UIImage imageNamed :@"Pause_40_40.png"] forState:UIControlStateNormal] ;
[self.playButton addTarget:self action:@selector(stop) forControlEvents:UIControlEventTouchUpInside];
isPlaying = true;
//Title of Music Screen
//self.title = titleOfTheSong;
//self.title = @"A Fixed Title";
MPVolumeView * volmueView = [[MPVolumeView alloc] initWithFrame:CGRectMake(60, 323, 200, 23)];
volmueView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:volmueView];
[[AVAudioSession sharedInstance] setDelegate:self];
e = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&e];
NSLog(@"Error: %@", e);
posUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(timeCounterUpdate) userInfo:self.player repeats:YES];
[self timeCounterUpdate2:self.positionSlider.value];
[self.player play];
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
NSLog(@"Finished");
if (flag == NO){
return;
}
[self.player pause];
[self.navigationController popViewControllerAnimated:YES];
}
我在 viewDidload 中将 avplayer 的名称设置为 player,然后对其进行检查,但它似乎仍然没有被调用
音频停止播放,但似乎仍在运行当前位置值确实停止了,但如果我暂停它然后播放它,按钮仍然显示好像音频仍处于播放模式,当前位置只是继续计数通过假定的结束文件。