kaytat / SimpleProtocolPlayer

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

Start streaming through am? #3

Closed kokoko3k closed 8 years ago

kokoko3k commented 8 years ago

I'm using a chroot environment and i'd like to start SimpleProtocolPlayer from it. I already wrote a script that allows me to start things outside the jail from the chroot environment, as simple as:

#chrooted> ./unchroot.exec.sh 'am start --user 0 -n com.kaytat.simpleprotocolplayer/com.kaytat.simpleprotocolplayer.MainActivity'

...but i'm really a noob in the android world, and the command above just starts your app, but the streaming is stopped. Is there a way to make it start streaming too by command line?

thanks.

kaytat commented 8 years ago

I have just pushed a new app to the play store that should allow you to do this. You will need this new app because this new one allows other applications outside SimpleProtocolPlayer to start the service.

So the first thing to note that SimpleProtocolPlayer is actually two components - there is the UI component (MainActivity) but there is also a background service that does the actual audio streaming (MusicService). Here's a link about services: http://developer.android.com/guide/components/services.html

So, you need to construct the am command line to start MusicService, not MainActivity. And you need to pass all the UI parameters to MusicService via the command line. In the code, this is done via intents (http://developer.android.com/guide/components/intents-filters.html). I wasn't sure if this was possible, but after poking around the source code for am (https://android.googlesource.com/platform/frameworks/base/+/742a67127366c376fdf188ff99ba30b27d3bf90c/cmds/am/src/com/android/commands/am/Am.java) it turns that in fact you can add the "extras" in the command line.

I have tested this locally by using the following commands:

adb shell am startservice -a com.kaytat.simpleprotocolplayer.action.PLAY -e ip_addr 192.168.3.7 --ei audio_port 12345 --ei sample_rate 12000 --ez stereo false --ei buffer_ms 50 com.kaytat.simpleprotocolplayer/.MusicService

and

adb shell am startservice -a com.kaytat.simpleprotocolplayer.action.STOP com.kaytat.simpleprotocolplayer/.MusicService

Note the use of startservice and .MusicService, and -e, --ei, and --ez to pass parameters.

Now, I don't have your exact environment with chroot, but if launching the UI works with your command line, then this should work to start the streaming.

kokoko3k commented 8 years ago

Thank you very much, this will be very helpful, and i will try it asap.

kokoko3k commented 8 years ago

It is working flawlessly, even without the main "gui", Great. Thank you.

amosbird commented 5 years ago

@kaytat Hi, I'm using this command to start the audio service

adb shell am startservice -a com.kaytat.simpleprotocolplayer.action.PLAY -e ip_addr 172.26.100.36 --ei audio_port 12345 --ei sample_rate 44100 --ez stereo true --ei buffer_ms 50 com.kaytat.simpleprotocolplayer/.MusicService
Starting service: Intent { act=com.kaytat.simpleprotocolplayer.action.PLAY cmp=com.kaytat.simpleprotocolplayer/.MusicService (has extras) }
Error: Not found; no service started.

However I have to open the GUI at first. Is there a way to start the service without GUI?