我正在開發一個應用程序,它使用AVAudioPlayer
播放聲音,我想知道聲音何時播放完畢。我想,當聲音停止播放如何判斷AVAudioPlayer播放完畢
下面是我用它來創建播放器的代碼更改圖像:
NSURL* url = [[NSBundle mainBundle] URLForResource:@"LOLManFace1" withExtension:@"mp3"];
NSAssert(url, @"URL is valid.");
NSError* error = nil;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&url];error;
if(!self.player)
{
NSLog(@"Error creating player: %@", error);
}
這裏是我用來播放聲音的代碼:
[self.player play];
我怎麼知道播放已完成?
非常感謝你提前!
嗨,感謝您的回答,我叫[自我audioPlayerDidFinishPlaying:self.player成功: YES]在我的按鈕動作,但在if語句導致我想知道聲音是否結束,但錯誤跳躍我怎麼能把這個如果能夠改變圖像? – 2014-09-02 17:09:17
您沒有正確使用它,請參閱https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html以查看協議和委託的工作流程 – Daniel 2014-09-02 17:47:23