【发布时间】:2013-04-13 06:04:50
【问题描述】:
我有这段音频播放器代码,但我不知道为什么 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,然后对其进行检查,但它似乎仍然没有被调用
音频停止播放但似乎仍在运行当前位置值确实停止 但是如果我暂停它然后播放它,按钮仍然显示好像音频仍处于播放模式,当前位置只是继续计数通过文件的假定结尾。
【问题讨论】:
-
感谢您的反馈,我正在尝试利用不再存在的人完成的现有代码。你能否给我一个关于如何解决的例子。我在为 iPhone 编程方面比较新,对此感到抱歉。
-
哦,对不起...好吧。如果您只想播放音频文件,则必须使用
AVAudioPlayer。另外,正如我刚刚在回答中确认的那样,您必须设置它的委托(否则将不会调用委托方法)。 -
好吧,我刚刚发现 AVAudioPlayer 不支持 HTTP 流。从这里查看这篇文章stackoverflow.com/questions/3413932/…
-
显然这是前任程序员忽略的一些遗留代码
标签: ios6 storyboard avaudioplayer