如何在AVAudioPlayer停止播放时调用方法

时间:2013-07-05 14:32:28

标签: objective-c avaudioplayer

当AVAudioPlayer停止播放时,我想知道并更改UIImageView。我正在努力,但我还没想到这一点。有什么办法吗?我的代码在

之下
 if ([[NSFileManager defaultManager] fileExistsAtPath:ttsOutWav]) {
    audioPath1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:ttsOutWav] error:&error];

    if (!error) {
        [audioPath1 play];

        NSLog(@"should be played");

    }
    else {
        NSLog(@"Error in creating audio player:%@",[error description]);
    }
}
else{NSLog(@"such file doesnt exist");}

2 个答案:

答案 0 :(得分:3)

我自己从未这样做过,但我希望您需要设置AVAudioPlayerDelegate委托类并实现以下方法:

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player
                       successfully:(BOOL)flag

答案 1 :(得分:1)

使用此委托方法,以便此方法将回调,

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{

}

以及解码时出错时的以下代理

- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
{


}

你也可以在这个网站上找到AVAudio Player的例子 http://iosdeveloperzone.com/2012/10/01/tutorial-playing-audio-with-avaudioplayer/