0

I've build a radio-app with CarPlay enabled. It worked great but somehow the artwork of a mpContentItem is not shown anymore. Please help me out here ;)

enter image description here

I read that there are maximum sizes for the images.

But still I'm not able to get the images back again. Both for the tabbar artwork and the item artwork (the logo of the radiostation). My code for creating a tabbar item:

func contentItem(at indexPath: IndexPath) -> MPContentItem? {

  let mpContentItem = MPContentItem()
        
  mpContentItem.title = radioStation[0]
  mpContentItem.subtitle = radioStation[1]
  mpContentItem.isStreamingContent = true
  mpContentItem.isPlayable = true
                                         
  let radioImage = loadImage(named: radioStation[3])
  let radioArtwork = MPMediaItemArtwork.init(boundsSize: radioImage.size, requestHandler: { (size) -> UIImage in return radioImage})

  mpContentItem.artwork = radioArtwork
        
  return mpContentItem

}

Can someone help me out here?

Update: this is the loadImage function

func loadImage (named: String) -> UIImage {
                
        if let confirmedImage = UIImage(named: named) {
            
            return confirmedImage
            
        } else {
            
            return UIImage(named: "defaultImage.png")!
            
        }
        
    }

Update: I use this code for the tabbar items:

let mpContentItem = MPContentItem(identifier: "landelijk")
mpContentItem.title = "landelijk"
mpContentItem.isContainer = true
mpContentItem.isPlayable = false
             
let radioImage = UIImage(named: "pijltjesCarplay")!
let radioArtwork = MPMediaItemArtwork.init(boundsSize: radioImage.size, requestHandler: { (size) -> UIImage in return radioImage.imageWith(newSize: size)})

mpContentItem.artwork = radioArtwork
            

return mpContentItem

See also my image asset screenshot:

enter image description here

  • What does your `loadImage(named:)` code do? What is the image size? You are running against iOS 16 right? – fruitcoder Dec 13 '22 at 21:14
  • I added the function in the post above. It loads an image within the app with a specific name. If the image is not present it return the default image. The size is 800x800. I experimented with smaller sizes but that didn't work. iOS 14 the code works fine. In iOS 15 and 16 is sometimes shows the images. Most of the time not. Or when you select a tab the image are gone. – Patrick Koning Dec 15 '22 at 09:02
  • With this [answer](https://stackoverflow.com/questions/66056233/how-to-set-artwork-image-for-mpnowplayinginfocenter) the images are shown finally. Only the tabbar items won't appear with this solution. – Patrick Koning Dec 15 '22 at 09:47
  • What sizes are your tab bar images. I guess it's easiest if you just used prerendered assets from you asset catalog (72px x 72px @3x) instead of resizing them at runtime (which might be the only way to make remote images work). – fruitcoder Dec 19 '22 at 10:41
  • I added the code I use for the tabbar items in the post above. – Patrick Koning Dec 20 '22 at 12:12
  • And a screenshot of my image assets. – Patrick Koning Dec 20 '22 at 12:21
  • It's confusing on Apple sites different resolutions are given. [This page](https://developer.apple.com/design/human-interface-guidelines/technologies/carplay/icons-and-images) says 108px x 108px or 26px x 23px @3. – Patrick Koning Dec 21 '22 at 09:20
  • Hm I don't have any projects using the old MediaPlayer framework (all migrated to CarPlay). The images I use are also in an asset catalog, 72 × 72 @3x and for Universal Devices (I used to play around picking CarPlay here but that was because the image lookup failed. Since you force unwrap that shouldn't be a problem). – fruitcoder Dec 21 '22 at 09:31
  • Apple's sample code is also just using the CarPlay framework. Just making sure you are using the `com.apple.developer.playable-content` entitlement and set `UIBrowsableContentSupportsSectionedBrowsing` to `true` right? Can you try using an SFSymbol and see if that shows up? `UIImage(systemName: "list.star")` – fruitcoder Dec 21 '22 at 09:44
  • Entitlement is correct and Browsing also. The "list.star" doesn't work. I found out that tabbar items are only loaded when starting a new CarPlay simulator. When reusing the simulator only the items are reloaded somehow. It's very weird why my code worked >= iOS 14. – Patrick Koning Dec 21 '22 at 10:34
  • You talked about not resizing the tabbar images. The function: MPMediaItemArtwork(image: UIImage) is deprecated. Can I use the MPMediaItemArtwork.init() without resizing? – Patrick Koning Dec 21 '22 at 10:36
  • I assumed you used the resizing function you mentioned in another comment (other SO post) for both the station images and the tab bar images. It's hard to say whether this is an simulator issue (it could very well be). Can you test on a real CarPlay device? If you have a minimal example project I could try it on my head unit test device – fruitcoder Dec 21 '22 at 11:18
  • I’ve some testers with CarPlay but I’ve to upload over and over a build. I’m questioning one now if the tabbar is back. I could add you to the TestFlight version. I looked on the internet and see that you have build a radio-app in Germany. Maybe we can contact via twitter or mail and help each other out? If you need some help sometimes of course :) – Patrick Koning Dec 21 '22 at 17:34
  • And … I use the resizing function. But also used the deprecated function. Both no succes. – Patrick Koning Dec 21 '22 at 17:37
  • May I ask why you are still using the legacy MediaPlayer framework? I remember having issues while supporting both versions where MP items in the root list weren't tappable on newer iOS versions so I completely switched over to CarPlay. You can contact me via twitter/mastodon if you want – fruitcoder Dec 22 '22 at 10:15
  • Good question ... just laziness ... it worked before so why change the code ;) Also working on a widget for the macOS app. I saw you build a beautiful radio-app also. I follow you on twitter (@pjkoning or @ned_radio). – Patrick Koning Dec 22 '22 at 16:57
  • That sounds interesting. How do you use the MediaPlayer api for a macOS widget? – fruitcoder Jan 02 '23 at 14:19
  • It shows the radiostations “last played”, “favorites” and “own added stations”. You can select an item in the widget then it starts the app. You can’t do play or pause etc. – Patrick Koning Jan 03 '23 at 09:06
  • You can see it partly in this video: https://stackoverflow.com/questions/74321672/widget-configuration-not-working-on-macos – Patrick Koning Jan 03 '23 at 19:50
  • @fruitcoder I've a question regarding the new CarPlay framework. Can you help me out? It would be nice if you mail me at info[@]radioned.nl. – Patrick Koning Jan 22 '23 at 12:02

1 Answers1

0

I finally stepped over to the new CarPlay framework with help of Fruitcode (thanks a lot). Everything works fine now.