MPMusicPlayerController does not send background notifications when using Apple Music (Sample Project is Included)

允我心安 提交于 2020-01-05 04:06:17

问题


This is a problem that has been bothering us for months now. I created a bug report for apple, but they aren't responding. I also created a sample project that demonstrates the bug. I would really appreciate any ideas that you guys have. So without further adieu, here is the description of the problem and a link to the sample project. Thank you so much!


Sample Project: https://dl.dropboxusercontent.com/u/28210/AppleMusicBug.zip

MPMusicPlayerController is used to play Apple Music songs via the new setQueueWithStoreIDs method. This was introduced when iOS 9.3 was released. The issue is that once you leave the app, these two notifications no longer fire and wake up our app:

MPMusicPlayerControllerPlaybackStateDidChangeNotification MPMusicPlayerControllerNowPlayingItemDidChangeNotification

The reason this is so so critical is that our app does not use exclusively Apple Music to play songs. We need to know when a song ends so that we can fire off code to play another song in our custom queue. Currently, this is impossible. We have attempted to use background tasks, but this does not work, as our methods does not work on background tasks. We need the same type of functionality that AVPlayerItem uses (AVPlayerItemDidPlayToEndTimeNotification) that will wake up our app when a song ends, regardless if the app is in the foreground or background. Without this, we can't use the API.

////////////////////////////////// Steps to reproduce //////////////////////////////////

  1. Install the app on an iPhone with an Apple Music Premium subscription. Ensure that the permission settings are open for the test app. Ensure that you are able to play a full song in the music app using your Apple Music subscription. (I understand you might not have a premium subscription. I'm not positive, but the issue should still be present if you are playing a song using MPMuiscPlayerController, however you are able to play that song)
  2. Open the test app.
  3. A popup should come up confirming that the app sees your apple music premium subscription. It should say "Great. Now play a song."
  4. Tap to play a song. The song should being playing in a few moments.
  5. Tap the home button to bring the app to the background.

At this point you will notice that the notifications (MPMusicPlayerControllerNowPlayingItemDidChangeNotification and MPMusicPlayerControllerPlaybackStateDidChangeNotification) will not fire. When the song that you play ends, the application is not notified. Furthermore, you'll notice that the lock screen controls do not work, and remoteControlReceivedWithEvent is not notified of these events as well. Only when you bring the app back to the foreground are the notifications such listed above fired. This needs to work in the background.


Thanks for helping us with the issue. If you would like to discuss the problem more in depth via email, you can reach me at gabe@cymbal.fm.

:)

来源:https://stackoverflow.com/questions/39621072/mpmusicplayercontroller-does-not-send-background-notifications-when-using-apple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!