我浏览了Apple开发的“音乐应用程序”示例,它使用MPMusicPlayerController从iPod库中获取歌曲,但是一旦应用程序进入后台并且不支持beginReceivingRemoteControlEvents,它就会停止播放该歌曲.
我检查了一些文章,说它使用AVPlayer,但它不支持从iPod库中获取音乐,因此当应用程序进入后台并且通过remoteEvents控制时,我陷入了如何播放音乐的困境.
解决方法 iPodMusicPlayer将在后台播放,但通过iOS iPod音乐播放器播放.您的应用不会在后台收到通知.为此,您需要设置AVAudioSession并使用AVPlayer.Check here for more information
Apple has a great resource here
来自Apple Docs:
Use an MPMusicPlayerController object,or music player,to play media items from the device iPod library. There are two types of music player:
The application music player plays music locally within your
application. It is not aware of the iPod app’s Now-playing item,nor
does it affect the iPod state.The iPod music player employs the
built-in iPod app on your behalf. On instantiation,it takes on the
current iPod application state,such as the IDentification of the
Now-playing item. If a user switches away from your app while music is
playing,that music continues to play. The iPod app then has your
music player’s most recently-set repeat mode,shuffle mode,playback
state,and Now-playing item.
确保你正在使用
+ iPodMusicPlayer
并不是
+ applicationMusicPlayer
Here is a good article on how to import the library into an AVAudioSession
在info.pList文件中添加一行,名称为“uibackgroundmodes”输入“audio”作为第一个键.
总结以上是内存溢出为你收集整理的objective-c – 当应用程序转到后台时,如何在自定义应用程序中播放来自ipod的音乐全部内容,希望文章能够帮你解决objective-c – 当应用程序转到后台时,如何在自定义应用程序中播放来自ipod的音乐所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)