如何让 avaudioplayer 在点击新歌时停止播放上一首歌曲?
我创建了一个带有按钮歌曲的视图。
- 当我们单击按钮时,它会转到一个包含列表的表 歌曲。
- 当我们选择一首歌曲时,它会转到另一个视图并播放该歌曲。
- 每当歌曲播放时,我们都可以返回主视图或主视图 歌曲将在背景中播放的歌曲表,最多可达 这里。
但是,每当我尝试播放歌曲表中的另一首歌曲时,上一首歌曲就不会停止,并且会继续与所选歌曲一起播放。
我的目标是在切换到不同视图时播放歌曲。我已经完成了这个,但我想要的是每当我从歌曲表中选择另一首歌曲时,它必须停止上一首歌曲并播放所选歌曲。
请解决这个问题。
I created a view with a button songs.
- When we click on button it goes to a table which contains list of
songs. - When we select a song it goes to another view and plays the song.
- Whenever the song is playing we can go back to main view or to the
table of songs the song will be playing in background its fine upto
here.
But whenever I try to play another song from the table of songs the previous song is not stopped and it continues to play along with the selected song.
My aim is play the song when it is switched to a different view. I have done this one but what I want is whenever I select another song from the table of songs it must stop the previous song and play the selected song.
Please solve this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须停止 avaudioplayer 并在释放现有实例后重新创建该实例。
如果您从表视图中进行选择,请将其放入
UITableView delegate
didSelectRowAtIndexPath
中:You have to stop the
avaudioplayer
and recreate the instance after releasing the existing one.If u are selecting from a table view put this in the
UITableView delegate
didSelectRowAtIndexPath
: