检测音频文件是否正在播放 - iphone
我正在使用调用方法的 UIButton 播放音频剪辑(请参阅下面的代码)。我试图弄清楚如何编写一个语句来检测音频是否正在运行,如果音频文件正在播放,则禁用/隐藏 UIButton。
此时,如果您继续触摸播放按钮,则会播放音频剪辑的多个实例。
-(void) audioMethod {
NSString *path = [[NSBundle mainBundle] pathForResource:@"affs" ofType:@"mp3"];
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
theAudio.numberOfLoops = -1;
[theAudio prepareToPlay];
[theAudio play];
}
感谢您的帮助
I'm playing an audio clip using a UIButton that calls a method (see code below). I'm trying to figure out how to write a statement to detect if the audio is running, and if the audio file is playing then disable/hide the UIButton.
At the moment if you keep touching the play button multiple instances of the audio clip play.
-(void) audioMethod {
NSString *path = [[NSBundle mainBundle] pathForResource:@"affs" ofType:@"mp3"];
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
theAudio.numberOfLoops = -1;
[theAudio prepareToPlay];
[theAudio play];
}
thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需将调用类声明为
AVAudioPlayerDelegate
(正如我看到您所做的那样)。然后编写一个方法:
并在开始播放声音时禁用该按钮:
You simply declare the calling class as
AVAudioPlayerDelegate
(as I see you have done).Then you write a method:
and disable the button when you start playing the sound: