Can not show album artwork on Carplay music

928 views Asked by At

I'm building an iOS Music app that can integrate with Apple Carplay, i can play music on Carplay normally and can display some information of song such as title, album, artist name. However can not display album artwork.

This is bulk code for display media information on Carplay:

     if let nowPlayingItem: PlaylistItem = self.nowPlayingItem {
        let info: NSMutableDictionary = NSMutableDictionary()
        info[MPMediaItemPropertyArtist] = nowPlayingItem.mediaItem?.artist?.name
        info[MPMediaItemPropertyAlbumTitle] = nowPlayingItem.mediaItem?.album?.title
        info[MPMediaItemPropertyTitle] = nowPlayingItem.mediaItem?.title
        info[MPMediaItemPropertyPlaybackDuration] = nowPlayingItem.mediaItem?.playbackDuration
        info[MPMediaItemPropertyArtwork] = nowPlayingItem.mediaItem?.artwork()
        let sec: TimeInterval = CMTimeGetSeconds(time)
        info[MPNowPlayingInfoPropertyElapsedPlaybackTime] = Int(sec)
        MPNowPlayingInfoCenter.default().nowPlayingInfo = info as? [String: Any]
    }

This is my current app:

enter image description here

And this is what i want :

enter image description here

So what i have to do ? Please help me to find solution for this.

2

There are 2 answers

0
fruitcoder On

You're likely testing on the simulator. While the following code is sometimes necessary to show the now playing screen at all, it is currently not possible to get the CarPlay simulator to figure out the player is actually playing:

#if targetEnvironment(simulator)
    UIApplication.shared.endReceivingRemoteControlEvents()
    UIApplication.shared.beginReceivingRemoteControlEvents()
#endif

I couldn't get the album artwork to show up on the now playing screen in the simulator. Do you have access to a physical car radio (I strongly recommend to test on one before submitting to the App Store)? I know it might not be very convincing but if your artwork shows up in the notification center player on the iPhone it will also show up in CarPlay (on a real device) since the now playing components are just proxied.

0
Antonio Junior On

you won't get the album cover when using the default CarPlay simulator from the Xcode simulator menu (I/O > External Displays > CarPlay), instead if you want to have more control over CarPlay screen you should use the simulator from Additional Tools (download it from the Apple Developer page).

You'll find the CarPlay simulator inside the Hardware folder.

Important: You need to build to a real device using the cable and Personal Hotspot should be toggled off.