11

I submitted Feedback about this in Feedback Assistant already, but figured I'd post here too -- as of iOS 13.4, I have noticed various bugs in the MediaPlayer framework, specifically with the applicationQueuePlayer and applicationMusicPlayer.

The first is that on app launch when it initializes, it now throws this error:

[SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded timeout [ping did not pong]

That error is followed by this one, when prepareToPlay() is called:

Error Domain=MPMusicPlayerControllerErrorDomain Code=6 "Failed to prepare to play" UserInfo={NSDebugDescription=Failed to prepare to play}

Eventually after calling prepareToPlay enough times it'll get its head on straight and start playing the content, but even then I'm finding I have to call play() or pause() several times for it to do so reliably.

Anyone else seeing this in their apps post-13.4?

alinder
  • 186
  • 7
  • 1
    I can confirm seeing this issue, but it is not consistent, most of the trials works, getting this error: `[SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded timeout [ping did not pong] [SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=9 "Preparing queue timed out" UserInfo={NSDebugDescription=Preparing queue timed out}` – Sherbieny Mar 31 '20 at 21:00
  • 1
    @Sherbieny I submitted a Feedback about this and it was updated today to say it will be fixed in a future OS update. – alinder Apr 01 '20 at 21:08
  • I am getting the same error. The situation is also the same. It wasn't solved with the 13.4.1 I guess. – amone May 17 '20 at 06:01
  • Getting the same error with 13.4.1 as well. Has anyone found a reliable workaround? I'm trying to play items from Apple Music. – Paulo Faria May 18 '20 at 01:04
  • I'm seeing the same error on iOS 13.5. – Estel May 26 '20 at 13:35
  • 2
    I too am experiencing "failed to prepare to play" on iOS 13.5.1. This is so frustrating. – Sol Jun 10 '20 at 17:07
  • I see this as well in 13.5.1 – HOTGS James Jun 13 '20 at 20:47
  • 1
    What I've done that seems to help is I've taken out the prepareToPlay call and added an additional pause() and play() call after my initial play() call. Hope it helps someone else. – HOTGS James Jun 13 '20 at 21:25
  • 3
    This happens to me on the iOS 14 dev beta as well. – Sol Jul 02 '20 at 19:09
  • Code 6 might be discrepancies between stores. Example DE vs US – Arnaldo Capo Jul 27 '21 at 10:35

2 Answers2

2

In my situation my player logic didn't always fire the player?.prepareToPlay() code. I make sure to stop() the player, then fire the prepareToPlay immediately after. Then I prep the player with the contentsOf: URL, and adjust the player settings, and then play. I also have some weird volume adjustments I had to add because of a popping sound that was happening. I'll post my player code below.

  static func play(sound: Sound) {
    
 
    stop()
    player?.prepareToPlay()

     let path = Bundle.main.path(forResource: sound.file, ofType: sound.extn)
        let url = URL(fileURLWithPath: path!)
    
    do {
        
        player = try AVAudioPlayer(contentsOf: url)
        player?.volume = 0 //starting volume at zero before playing eliminates pop on start
        player?.numberOfLoops = -1
        player?.play()
        player?.setVolume(1, fadeDuration: 0.3)  //fade in, no pop

    } catch {
      print(error)
    }
}
Dave Levy
  • 1,036
  • 13
  • 20
1

For a number of days now, I've been scratching my head as to why I wasn't able to play store identifiers for Apple Music catalog or library content. Turns out, setting the store identifiers directly with MPMusicPlayerApplicationController will play the content, whereas using MPMusicPlayerStoreQueueDescriptor and passing it to MPMusicPlayerApplicationController results in no effect.

I still get the following error logs:

[SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded timeout [ping did not pong]

[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""

iTunesCloud] ACAccountStore 0x283e1bdb0 - Error retrieving iTunesStore accounts. err=Error Domain=com.apple.accounts Code=9 "(null)"

[iTunesCloud] [ICUserIdentityStore] Failed to fetch local store account with error: Error Domain=com.apple.accounts Code=9 "(null)".

...but gone is Error Domain=MPMusicPlayerControllerErrorDomain Code=6 "Failed to prepare to play" UserInfo={NSDebugDescription=Failed to prepare to play}.

Hopefully this might be useful for someone else who stumbles into this :)

Here's some code so you see what I mean:

class AMPlayer {

    private(set) var player: MPMusicPlayerController!
    // Every time `queue` is set, it'll ensure the player queue is "updated"
    private var queue: MPMusicPlayerStoreQueueDescriptor! {
        didSet {
            guard self.queue != nil,
                  let storeIDs = self.queue.storeIDs,
                  !storeIDs.isEmpty
            else { return }

            self.player.setQueue(with: storeIDs)
        }
    }
    
    // This is how I set the queue from outside the class
    public func setQueue(with resourceIDs: [String]) {
        self.queue = MPMusicPlayerStoreQueueDescriptor(storeIDs: resourceIDs)
    }

    // This is how I start playback
    public func play() {
        self.player.prepareToPlay { (error) in
            if let error = error as? MPError {
                print("Error while preparing to play: \(error)")
            } else {
                self.player.play()
            }
        }
    }

}