kaytat / SimpleProtocolPlayer

Audio player for uncompressed PCM data
Apache License 2.0
108 stars 22 forks source link

Start on system boot/run as a service #35

Open mad-ady opened 2 months ago

mad-ady commented 2 months ago

Hello!

Your SimpleProtocolPlayer was the final piece in my puzzle! I'm running Linux inside a Docker container on top of Android TV (on an Odroid N2+), and I'd like to run mpd inside the linux image and have audio play back via the Android speakers. I've installed pulseaudio on the linux side and I'm running it as: /usr/bin/pulseaudio --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --load="module-simple-protocol-tcp source=0 record=true port=12345" --exit-idle-time=-1 --system. I've sideloaded your SimpleProtocolPlayer, which runs just fine and I'm able to get audio, and it feels ok.

My request would be to have a way to start SimpleProtocolPlayer, ideally without a GUI, on system startup, and have it try to connect to the pulse audio server on its own.

Is this something that already works, or is it something that is easily doable (I have root access at the Android level, so I was thinking of starting a daemon/service or something similar)?

Thanks!

kaytat commented 2 months ago

The way Android makes you write media apps, there is already a split between the GUI and the service that is playing the audio. And so it sounds like the request here is to make audio playback service start on boot and have it try to connect to the last known pulseaudio server. And have it running in the background all the time.

This is not in progress. I also don't have a good handle of "doable" because Android has been increasingly limiting what apps can do in the background and for how long.

But if it can be confirmed that Android would allow this behavior, then I think the audio service could be started automatically.

mad-ady commented 2 months ago

Sorry for my delay in reply!

I am able to start the application via a startup service (I'm on a rooted device), with this command, and inject the taps necessary to press the Play button:

sleep 10
# start simple protocol player
am start -n com.kaytat.simpleprotocolplayer/com.kaytat.simpleprotocolplayer.MainActivity
# press play
sleep 3
/system/bin/input tap 890 1079
# go back to launcher
sleep 2
/system/bin/input keyevent KEYCODE_HOME

The settings seem to be unchanged since last startup, which is great, however, I don't know if there is an easy way to "press Play" and start the service. My method works, but seems hacky...

Is there an elegant way of starting the service programmatically?

Thanks!