如何判断AVAudioPlayer已经播放完毕 [英] How to tell that AVAudioPlayer has finished playing

查看:88
本文介绍了如何判断AVAudioPlayer已经播放完毕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 AVAudioPlayer 播放声音的应用,我想知道声音何时播放完毕.我想在声音停止播放时更改图像

I'm developing an app that plays sounds using AVAudioPlayer, and I want to know when a sound has finished playing. I want to change an image when the sound stops playing

这是我用来创建播放器的代码:

Here's the code I use to create the player:

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);
}

这是我用来播放声音的代码:

And here's the code I use to play the sound:

[self.player play];

我如何知道播放已完成?

How can I tell that playback has finished?

非常感谢您!

推荐答案

查看AVAudioPlayerDelegate协议,该协议具有一种方法,可以告诉委托人音频播放何时完成,尤其是您要查找的是-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)播放器成功:(BOOL)flag ,这是一个

Look at the AVAudioPlayerDelegate protocol which has a method to tell the delegate when audio playback has finished among other things, specifically what you are looking for is - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag, here is a reference

希望有帮助

丹尼尔

这篇关于如何判断AVAudioPlayer已经播放完毕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆