79389530

Date: 2025-01-27 00:35:36
Score: 1
Natty:
Report link

For future reference, here's what I learned while trying to get this working:

I have the album art loading now and it will play the mp3 files. For the album art, I was creating the Uri with the fromFile method, instead of the parse method. That was messing up the path. I adjusted and called the mapUri method in the ContentProvider that I copied from the uamp sample. It was trying to get the content from a web address and my app gets the content from a local file. The path needed to look like this content://data/data/com.emrick.dj/albumart/album.jpg.

I had been testing the play function by putting a break point on the onPlay method in the mediaSession.setCallback. It never hit the breakpoint - then I realized it was actually calling the onPlayFromMediaId method, not onPlay. I wrote that method and then the breakpoint on it was reached. I wired it to my existing MediaService (for the mp3 player) but it didn't play. Then I realized it had to handle the audio focus. Apparently the Windows Head Unit takes the audio focus away from my mp3 player. I changed my mediaService to ask for the audio focus and then it would play my mp3 files.

It took a lot of work to get to this point - I could have really used a complete example in Java, not Kotlin. Lots of details that weren't obvious to me. Anyway, I hope these notes help others trying to get this to work! Thanks Ben Sagmoe for pointing me in the right directions.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • No code block (0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: user3573712