MPMusicPlayer Error Domain=MPErrorDomain Code=4?
Asked Answered
E

1

7

I am having issue with Music player, most of the songs gives Error

Error Domain=MPErrorDomain Code=4

The testing device has Apple music subscription and the tracks gives error on the app they are working fine in Apple music app!

Here is the code:

let applicationMusicPlayer = MPMusicPlayerController.systemMusicPlayer()
 applicationMusicPlayer.setQueueWithStoreIDs([ID])

      if #available(iOS 10.1, *)
      {

        applicationMusicPlayer.prepareToPlay { (error) in

            if (error != nil)
            {
                print("[MUSIC PLAYER] Error preparing : \(String(describing: error))")
                return
            }else
            {
                self.start_timer();
                self.applicationMusicPlayer.play()
            }

        }

      }else
      //Play directly ios below version 10.1
      {
        self.applicationMusicPlayer.play()
      }

    }

But what I've tried, when the track gives this error, I went to Apple music player and played it from there its worked, then I came back to my app and play it from my app its worked also fine, so I need to go to Apple music app to play tracks not playing in my app to make them work in my app! That's so weird any idea why?

PS: the testing device has Apple music subscription

Eldaelden answered 4/9, 2017 at 9:40 Comment(5)
Are the songs that give the error downloaded to the device? Or are they in the users library but not downloaded to the phone?Marriage
@MicahWilson the songs from remote API , it provide apple songs with epf_id <-- store ID in apple , some are works and most of them are not gives the error aboveEldaelden
But when i go to apple music and play it from there it played , then we i came back to the app and play it from my app its playing also without errorsEldaelden
I receive the exact same error from similar code. I would recommend opening a radar with Apple about it (I have) as MPMusicPlayerController has been seriously messed up for a while and needs to be fixed.Mauney
@Mauney i found a solution for this after spending days on it check my question here #46022873Eldaelden
M
7

I had some similar problems when adding songs to a playlist, solved it by using:

DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) {
    // Code
}

i would play around with waiting a bit before or after preparing.

5 seconds may be too much, but you can start from there

Mikvah answered 16/10, 2017 at 2:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.