Play toutchscreen

Post Reply
ElmodiLatta
Posts: 21
Joined: Mon Sep 15, 2025 10:11 am
Location: Italy

Play toutchscreen

Post by ElmodiLatta »

Hi,
I have the following problem: Arduino sends the processed CAN-bus signals to the Raspberry Pi, which, via a Python script, manages the day/night, reverse camera, and play, track forward/backward functions. Day/night, and reverse camera functions work immediately. However, the multimedia controls don't work until I press play on the touchscreen. Can you give me some pointers on what to check?
Thanks
hudiy
Site Admin
Posts: 440
Joined: Mon Jul 14, 2025 7:42 pm

Re: Play toutchscreen

Post by hudiy »

In Hudiy, no player is started automatically by default.

When you press Play in any player, it makes an audio-focus request (so multiple players can't play at the same time) and registers itself as the Now Playing media source. This applies to every player - Android Auto, CarPlay, Storage, FM Radio, A2DP and Web - as soon as it starts playing audio.

Until a player actually begins playing, the audio focus and Now Playing media remain unset.

In Hudiy's settings (Settings -> Audio -> Sound), you can enable automatic playback for FM Radio and Storage. Android Auto, CarPlay, A2DP and Web manage their own auto-start behavior independently.

https://github.com/wiboma/hudiy/blob/ma ... n.md#sound (storageMusicAutoplay, fmRadioAutoplay)
ElmodiLatta
Posts: 21
Joined: Mon Sep 15, 2025 10:11 am
Location: Italy

Re: Play toutchscreen

Post by ElmodiLatta »

Thanks, I'll try to understand how the audio-focus works.
hudiy
Site Admin
Posts: 440
Joined: Mon Jul 14, 2025 7:42 pm

Re: Play toutchscreen

Post by hudiy »

The API documentation sheds more light on how audio focus works in Hudiy. All players implemented by Hudiy follow this protocol:

https://github.com/wiboma/hudiy/blob/ma ... proto#L429
https://github.com/wiboma/hudiy/blob/ma ... proto#L501
https://github.com/wiboma/hudiy/blob/ma ... proto#L512
https://github.com/wiboma/hudiy/blob/ma ... proto#L547

The main purpose of the audio-focus mechanism is to prevent multiple players from playing at the same time, give priority to communication streams such as phone calls and manage volume when a notification, for example navigation guidance, needs to play the audio.
ElmodiLatta
Posts: 21
Joined: Mon Sep 15, 2025 10:11 am
Location: Italy

Re: Play toutchscreen

Post by ElmodiLatta »

Hi,
I started working on the audio focus. I get "Attempting to register AudioFocus as a Raspberry audio controller." I then get "register audio focus receiver response, result: 1, id 22." The ID changes every time I run the script.
Fig1.png
Fig1.png (120.48 KiB) Viewed 1088 times
When I press the Play (PL) button, I get "executing _send_toggle_play_focus (ID:22)," "attempting to send GAIN FOCUS REQUEST," "audio focus change response, result: True id:22," "[audiofocuskey] sent: toggle_play (press and release) with id 22," but nothing happens.
Fig2.png
Fig2.png (60.82 KiB) Viewed 1088 times
What am I forgetting? Sorry for the English and the writing, which is mixed in Italian and English.
Thanks
hudiy
Site Admin
Posts: 440
Joined: Mon Jul 14, 2025 7:42 pm

Re: Play toutchscreen

Post by hudiy »

Could you please describe in detail what effect you're trying to achieve? The Audio Focus API is mainly intended for cases where you want to build your own music player and integrate it with Hudiy (with existing Audio Focus engine).
ElmodiLatta
Posts: 21
Joined: Mon Sep 15, 2025 10:11 am
Location: Italy

Re: Play toutchscreen

Post by ElmodiLatta »

Hi,
My Mini Cooper has an Arduino Nano installed that translates CAN-BUS messages into messages that can be read by the Raspberry Pi 5. The point where I connected the Arduino to get the CAN-BUS signals is inconvenient for connecting the Raspberry Pi. The two communicate via serial. The commands are the usual PLAY (PL), NEXT (NT), PREV (PT), then there are the day/night and rear-view camera controls. What doesn't work is that until I press play on the touchscreen (Spotify, Vitune, I've also tried other apps), the steering wheel controls don't work. Once I press play, everything works perfectly.
Thanks
hudiy
Site Admin
Posts: 440
Joined: Mon Jul 14, 2025 7:42 pm

Re: Play toutchscreen

Post by hudiy »

For that purpose, you don't need to use the AudioFocus API - simulating keyboard events or using an API to inject them is sufficient.

By "Spotify" do you mean Spotify running in Android Auto or CarPlay?

In case of projections, they typically register themselves as audio focus receivers and request focus only when playback actually starts. Until one of the players requests audio focus, Hudiy does not know where forward multimedia key events - that's why keys start working only after (any) playback begins.

The solution is to enable automatic music playback when the projection starts. Android Auto includes this option in its settings and as far as we know, CarPlay resumes the previous playback state - if music was playing before disconnection, it will automatically resume upon reconnection.
ElmodiLatta
Posts: 21
Joined: Mon Sep 15, 2025 10:11 am
Location: Italy

Re: Play toutchscreen

Post by ElmodiLatta »

I tried simulating key presses or mouse clicks, but I can't find any Python libraries compatible with WayLand. For now, I automatically start music with Android Auto, and I stop it if I don't want to listen to it.
I switched to Trixie. Previously, I automatically started my Python file in /etc/xdg/labwc/autostart, but now it doesn't work anymore. I had to create a .service file in ets/systemd/system to make it work. Has anything changed between Bookworm and Trixie in this regard?
Thanks
hudiy
Site Admin
Posts: 440
Joined: Mon Jul 14, 2025 7:42 pm

Re: Play toutchscreen

Post by hudiy »

ElmodiLatta wrote: Sat Nov 15, 2025 1:37 pm I switched to Trixie. Previously, I automatically started my Python file in /etc/xdg/labwc/autostart, but now it doesn't work anymore. I had to create a .service file in ets/systemd/system to make it work. Has anything changed between Bookworm and Trixie in this regard?
Thanks
Autostart should work the same way on Bookworm and Trixie. The only difference is that Hudiy is now started from $HOME/.config/labwc/autostart. It will help to avoid conflicts in future OS updates as /etc/xdg/labwc/autostart is the system file and may be overwritten by the OS.
Post Reply