0
我想檢查音頻是否已結束播放。如果是這樣,我需要將按鈕更改爲播放按鈕而不是暫停按鈕。我如何在iOS中執行此操作?檢查音頻是否已經結束播放iOS
我的代碼如下所示:
-(void)playAudioFile:(BOOL)status
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"audio" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSError *error;
if(status)
{
if(!audioPlayer)
{
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:&error];
audioPlayer.currentTime = currentPlayTime;
audioPlayer.numberOfLoops = 0; //Infinite
audioDuration = audioPlayer.duration;
audioPlaySlider.minimumValue = 0;
audioPlaySlider.maximumValue = audioDuration;
audioPlaySlider.value = currentPlayTime;
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(audioTimer:) userInfo:[NSDictionary dictionaryWithObject:audioPlayer forKey:@"playerObject"] repeats:YES];
}
[audioPlayer play];
if([audioPlayer rate] != 1.0)
{
[audioPlayer play];
}
else
{
[self->audioPlayBtn setBackgroundImage:[UIImage imageNamed:@"playBtn.png"] forState:UIControlStateNormal];
}
NSLog(@"Play duration : %f",audioDuration);
}
else
{
if(audioPlayer && audioPlayer.playing)
{
[audioPlayer pause];
}
}
NSLog(@"Error for file : %@",error);
}
我嘗試這樣做:
if([audioPlayer rate] != 1.0)
{
[audioPlayer play];
}
else
{
[self->audioPlayBtn setBackgroundImage:[UIImage imageNamed:@"playBtn.png"] forState:UIControlStateNormal];
}
但沒有工作..需要一些指導...