Closing app doesn't stop playback when using MPMusicPlayerController.applicationMusicPlayer

Originator:jay.whitsitt
Number:rdar://35570957 Date Originated:November 15 2017
Status:Open Resolved:
Product:iOS + SDK Product Version:MusicKit on iOS
Classification:Bug Reproducible:Always
 
Summary:
applicationMusicPlayer and applicationQueuePlayer can't be controlled from the Music app and are only accessible from the host app, not even in Control Center. However, when the app is closed either by the user, crash, or stopping it in Xcode, the song will continue playing. This creates a scenario where the user is unable to stop playback.

Attached is the sysdiagnose. This was reproduced at 4:01 pm CST.

Steps to Reproduce:
1. Get an instance of MPMusicPlayerController.applicationMusicPlayer or .applicationQueuePlayer
2. Queue and prepare to play a song (e.g., [player setQueueWithStoreIDs:@[@"295757262"]])
3. [player play]
4. Force close the app

Expected Results:
Music stops

Actual Results:
Music continues playing and the user cannot stop playback unless
1. The song plays until the end
2. The user plays a different song somewhere else

Version/Build:
iOS 11.1.1, 11.2 beta 3

Configuration:
iPhone 6, iPhone X

Comments

Fixed

Try this in the app delegate. However, if your app is suspended, this method will not be called. But if your app is suspended I doubt it's playing music anyways.

  func applicationWillTerminate(_ application: UIApplication) {
           print("Application Will Terminate")

          if musicPlayerController.playbackState == MPMusicPlaybackState.playing {
              musicPlayerController.stop()
          }
    }

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!