如何使用 AVAudioPlayer 的单个实例来播放多首歌曲?
我想用 AVAudioplayer 的单个对象播放多首歌曲,我将歌曲放在表行中,当用户点击行播放器视图打开时,但当用户返回表播放器中的其他行时,会同时播放两首歌曲。我可以做什么来解决这个问题?
I want to play multiple songs with single object of AVAudioplayer, I put songs in table row , when user tap on row player view is open but when user go back in other row in table player play both songs simanteniosly . what I Can do to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您已在 h 文件中创建了该对象,并声明并合成了它的属性。
此外,您可能正在通过 didSelectRowAtIndexPath: 方法播放文件。在该方法中,您可能有以下代码部分。
在[appSoundPlayer prepareToPlay];之前添加[appsoundPlayer stop];只是为了确保音频播放器在开始播放会话之前处于停止状态。
如果您采用不同的方法,只需在此处发布代码的相关部分,
I assume that you have created the object in the h file, and have property declared and synthesized it.
Also you might be playing the file from didSelectRowAtIndexPath: method. In that method you might have the following section of code.
Before [appSoundPlayer prepareToPlay]; add [appsoundPlayer stop]; just to ensure that the audioplayer is in stop state before starting the playing session.
If you are following a different method, just post the relevant part of the code here,
AVAudioPlayer
用于播放单个音频剪辑。如果您想播放不同的剪辑,请停止当前播放器,使用新的音频数据制作一个新的剪辑,然后播放。如果两首歌曲重叠,那么您可能不小心创建了两个
AVAudioPlayer
实例,并且未能停止第一个实例。An
AVAudioPlayer
is meant to play a single audio clip. If you want to play a different clip, stop the current player, make a new one with the new audio data, and play it.If two songs are overlapping then you're probably accidentally making two
AVAudioPlayer
instances and failing to stop the first one.