0

How to load image asynchronous from sdwebimage to MPMediaItemArtwork in MPNowPlayingInfoCenter ?

MPMediaItemPropertyArtwork: MPMediaItemArtwork(boundsSize: CGSize(width: 200, height: 200), requestHandler: { (size) -> UIImage in

     let fakeImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
     fakeImageView.sd_setImage(with: thumbURL, completed: { (image, error, cache, url) in

            if (error != nil) {
                return UIImage(named: "no_artwork") // i cannot return this
            } else {
                return image // i cannot return this
            }

     })

     return ... // how access to image from sdwebimage

})

i can not return image from inner function. how to fix this?

Farzad
  • 1,975
  • 1
  • 25
  • 47

1 Answers1

1

Well from the code you provided the closure of the sd_setImage method has the void return, you cannot define non-void return value there.

However you could define the MPMediaItemArtwork inside of the closure. That's the time an image is available to you.

Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84