MPMusicPlayerController does not work on iOS 11.3 Beta

Apple music does not work on iOS 11.3 Beta. It was working on iOS 11.2.5 though.


I am playing Apple music in my application using two ways using setQueueWithMPMediaItemCollection and setQueueWithStoreIds. First one is working fine but second method is not working at all and there is no error occurrs but music is not playing.


// Code snippet

let appleMusicPlayer : MPMusicPlayerController = MPMusicPlayerController.applicationMusicPlayer()

// Method 1

self.appleMusicPlayer.setQueue(with: MPMediaItemCollection(items:[appleMediaItem]))

// Method 2

self.appleMusicPlayer.setQueueWithStoreIDs([trackId])



any help will be highly appreciated.

Replies

Several MPMusicPlayer issues are fixed in iOS 11.3 Beta 2. But in order to see the fixes, I had to use the corresponding xcode beta. Apps compiled with Xcode GM still exhibit strange behavior when running on iOS 11.3 Beta 2.

I too am having problems with iOS 11.3 even when using Beta 2 and the corresponding xcode beta.


My problem is that the audio will begin playing as soon as prepareToPlay is called. Consider the code below:


  spinner.startAnimating()
  appMusicPlayer.prepareToPlay(completionHandler: {[weak self] (error) in
      self?.appMusicPlayer.currentPlaybackTime = ct
      DispatchQueue.main.async { [weak self] in
            self?.spinner.stopAnimating()

            if error != nil {
                self?.goIdle()
                let alertController = UIAlertController(title: "Problem Playing Apple Music", message:
                      "Check network connection and try again.  " + error!.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)
                alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default,handler: nil))
                self?.present(alertController, animated: true, completion: nil)
            } else {
                self?.conditionallyBeginFadeIn()
                self?.appMusicPlayer.play()
                self?.playbackStartTime = (self?.appMusicPlayer.currentPlaybackTime)!
                self?.playbackStartDate = Date()
            }
      }
  })


Normally (like with iOS 11.2 and prior) the audio playback doesn't begin until the call to "appMusicPlayer.play()" in the completion handler. But with iOS 11.3 Beta 2, it will begin as soon as prepareToPlay is called.


I'm also noticing inconsistent problems getting and setting "currentPlaybackTime" as well.

I'm seeing the same with iOS 11.3 beta 3. They've come so far with the MPMusicPlayer issues! Just a few remaninig. I've submitted bug report 37786167 for the issue with autoplay on .prepareToPlay().


If you can narrow down the issue with currentPlaybackTIme or second my bug report on prepareToPlay(), it's always good to have more voices who can clearly demonstrate the bugs.

Sorry, I just saw your reply today (I wasn't notified earlier and I just happened to check back here today).


I submitted a bug report (my first one so I hope I did everything correctly) on the issue with prepareToPlay so hopefully that will provide one more voice.


The problem with currentPlaybackTime has been hard for me to reproduce consistently. In practice, when things are working properly, I set the currentPlaybackTime to where I want playback to begin and it works fine. With 11.3 Beta 3, it will sometimes work and sometimes not work. I haven't been able to narrow it down. Since it seems logical to think that this might be related to problems with playback preparation, I thought I'd see if the fix to prepareToPlay would also address this inconsistent issue.

We also have been having several issues with 11.3 beta. We have determined that the first time we start our app (after a power on) we have several issues with missing media player notifications, getting currentPlaybackTime, etc. However if we terminate our app and then start it up again many of these issues are gone. Or if we start the Apple Music App (and play some music) before starting our app after a power up, many of the issues are also gone.


I've submitted a bug report with logs but have not had any feedback yet.


This could be leading to your inconsistant results. Would be interested in your results after trying this.

Still active in iOS 11.3 beta 4 15E5201e / Xcode 9.3 beta 4 9Q127n (released 3-5-18), I'm still seeing the "autoplay" bug when .prepareToPlay() is called. Also, I can't set currentPlaybackrate on the MPMusicPlayer. Anyone else having this trouble?


I've submitted bug reports on both and updated with attempts with iOS11.3 beta 4.

I'm seeing the exact same behaviour. If the system player has a nowPlayingItem on app launch I get one set of behaviours, and if not I get an entirely different experience (dropped notifications, SDKPlayback timeouts, etc).


I sincerely hope this is resolved in b5.

I just updated bug report with failed attempts on beta 4 also.


I am not hopeful that they will fix these bugs. The last few bug reports we submitted for the MusicPlayer SDK never got fixed nor did we get any feedback from Apple. We had to find workarounds for these, including the 11.2 freeze issues.


Can someone from Apple please respond to these issues we are now having?????

Having the same Problem with MPMoviePlayerController, since 11.3 Beta 4


Getting MPMovieFinishReasonPlaybackError, Error Code 3 immediately at start.

In iOS 11.3 beta 5 15E5211a, I'm still seeing both issues:

1) prepareToPlay causes autoplay and (bug #37786167)

2) currentPlaybackrate is ignored when setting on active MPMusicPlayer (bug #38126022)


If anyone else has active bug reports on these or other MPMusicPlayer, please update with the latest beta build info.


@ ross.woodhams - regarding your original post, the documentation for both setQueue & setQueueWithStoreIDs say that prepareToPlay has to be called after setting the queue. That in turn causes the audio to play. Are you still having the original issue of no tracks playing at all?

We are seeing improvement with Beta 5. We are now seeing the MusicPlayer notifications, the playback time getting updated, and no freeze when starting to play a song. We have confirmed this on 3 different iPhones. However the first time we ran Beta 5 on an iPad we saw the original issues. We have since restarted the iPad several times and the problem has not reappeared. Will keep you posted as we continue to test.

I don't have much to add other than to say that I have tested my app with 11.3 beta 5 and I too am still seeing no improvement. I just wanted everyone on this thread to know that I'm still testing and still hopeful for a resolution.

As of the public release of 11.3, the prepareToPlay still starts playing immediately and the setCurrentTime works very inconsistantly. Working on workarounds right now, but there will be some very unhappy folks using my production app when they upgrade to 11.3.

    appleMediaResults = AppleMusicHelper.getMediaQueryFor(musicCollectionSpecificItem: music).collections
    if let media = appleMediaResults {
        appleMusicPlayer.setQueue(with: media[0])
        appleMusicPlayer.beginGeneratingPlaybackNotifications()
        NotificationCenter.default.addObserver(self, selector: #selector(appleNowPlayingChanged), name: NSNotification.Name.MPMusicPlayerControllerNowPlayingItemDidChange, object: nil)
        if #available(iOS 10.1, *) {
            appleMusicPlayer.prepareToPlay { error in
                if let error = error {
                    print("Apple Music Player Error: \(error.localizedDescription)")
                    return
                }
                self.appleMusicPlayer.shuffleMode = Settings.musicShuffleOn ? .songs : .off
                self.appleMusicPlayer.repeatMode = .all
                self.appleMusicPlayer.play()
            }
        }
    }


After some trial and error, the above seems to work. Unfortunately, it only works for iOS 10.1 or newer versions because of the `prepareToPlay` callback function.

With iOS 11.3 general release, are others still seeing:?

1) prepareToPlay causes autoplay and (bug #37786167)

2) currentPlaybackrate is ignored when setting on active MPMusicPlayer (bug #38126022)


If so, please submit bug reports.