使用 MPMoviePlayerController 实现连续背景音频?
我正在使用 MPMoviePlayerController 来播放流音频。我正在尝试让背景音频正常工作。现在,当您退出应用程序时,音频会继续播放 - 锁定屏幕和多任务栏控件甚至可以工作。
当一首歌曲结束时,应用程序应该前进到下一首曲目并播放它。它在应用程序打开时起作用,但在后台运行时不起作用(歌曲完成但不会前进到下一首曲目)。但是,如果一首歌曲播放完毕并且您重新打开应用程序,下一首歌曲将立即开始。
我目前正在使用 NSNotificationCenter 来跟踪曲目何时结束以前进到下一个曲目(在我的应用程序委托中)。同样,当应用程序打开时,它就像一个魅力。有没有更好的方法可以在歌曲播放完后保持音频播放?
I am using MPMoviePlayerController to play streaming audio. I'm trying to get background audio working correctly. Right now, audio continues to play when you exit the app - the lock-screen and multi-tasking bar controls even work.
When a song finishes, the app is supposed to advance to the next track and play it. It works when the app is open but not when it is in the background (a song finishes but does not advance to the next track). If a song finishes and you re-open the app, however, the next song will start up immediately.
I am currently using NSNotificationCenter to keep track of when tracks end to advance to the next track (in my app delegate). Again, it works like a charm when the app is open. Is there a better way to do this to keep audio playing after a song is done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近遇到了这个问题。希望答案对其他人有帮助。
例如,如果您有一个播放列表,并且想要在后台模式或锁定模式下播放下一首歌曲,请在 viewDidLoad 上添加以下代码行:
这使得应用程序支持远程控制事件。
I had this issue lately. Hope the answer helps other people.
If you have a playlist for example and want to play the next song while in background mode or lock mode add this line of code on your viewDidLoad:
This makes the app supports remote control events.