MPMediaItem artwork to base64

Has anyone tried converting a MPMediaItem artwork to base 64? Most of the solutions I tried ended up in a plain black image.

Hello @reinhardholl,

What are you trying to do? We need more information about your use-case so we might be able to give you good advice.

Thanks,

Sorry Joe, my question was lacking a lot of context.

I am trying to create a React Native bridge. Everything is working well, I am just finding it hard to send back image data from the SDK. I thought using base64 might just be the easiest as our image library easily supports this.

I was trying something along these lines. I quickly put this together so ignoring null checks etc:

  private func getBase64ImageFrom(item: MPMediaItem) -> String {
    let image = item.artwork?.image(at: CGSize(width: 300, height: 300))
    let imageData = image!.pngData()
    let base64Image = imageData!.base64EncodedString()
    return base64Image
  }

I do get a PNG image back, but its just a black square rathe than the expected artwork. Any ideas?

Hello @reinhardholl,

Aside from the fact that using the force-unwrap (!) operation like you're doing is very dangerous and could lead to crashes in your app, I don't see anything wrong with your approach.

Would you be able to file a ticket on Feedback Assistant with a little sample app exhibiting the problem? We're especially interested in seeing how you're getting this MPMediaItem.

Thank you very much in advance.

Best regards,

MPMediaItem artwork to base64
 
 
Q