我浏览了Apple开发的“音乐应用程序”示例,它使用MPMusicPlayerController从iPod库中获取歌曲,但是一旦应用程序进入后台并且不支持beginReceivingRemoteControlEvents,它就会停止播放该歌曲.
我检查了一些文章,说它使用AVPlayer,但它不支持从iPod库中获取音乐,因此当应用程序进入后台并且通过remoteEvents控制时,我陷入了如何播放音乐的困境.
解决方法
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