Playing audio file remotely

Share and discuss your flows and ideas with other users.

Moderator: Martin

Post Reply
phenning
Posts: 6
Joined: 18 Dec 2015 04:25

Playing audio file remotely

Post by phenning » 27 Feb 2020 19:04

My goal is to play an MP3 file remotely on an Android tablet. I see two possibilities:

1. MP3 File upload to the tablet, then play with local media player. Is there any good (tested) flow for such an upload ? I haven't found one so far.

2. Writing the MP3 to a local DLNA Server with disabled caching. This works pretty well with my BOSE boxes: I create the MP3, push it to the DLNA Server and then just tell my BOSE box "play fhemspeech". On a tablet running Automagic I would therefore need a good DLNA renderer to be operated by Automagic. Is there any app/flow combination working along this line? A search for DLNA does not return anything useful.

Best regards

Peter Henning

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Playing audio file remotely

Post by Desmanto » 01 Mar 2020 18:49

This should be in user help section.

What is the sender device? Another android device with Automagic installed? Or PC?
You can use HTTP request Trigger. This will host a web server, which you can upload the mp3 file. If the other device is android with Automagic too, then you can use action http request - POST to upload the mp3. Then at the tablet, will receive the file and play the file using action Sound.

Automagic doesn't support DLNA, so that won't be the option. I don't know if there is a flow to demonstrate this yet. Need to know your uploader device detail first (is it android or PC).
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

BoBo
Posts: 129
Joined: 05 May 2014 12:45

Re: Playing audio file remotely

Post by BoBo » 13 Mar 2020 13:11

You can use HTTP request Trigger. This will host a web server, which you can upload the mp3 file. If the other device is android with Automagic too, then you can use action http request - POST to upload the mp3.
Thx for that hint. Nevertheless, I wasn't able to get that running on my own, or find a code/flow snippet about that at the forum. Would you mind to give further advice/a sample flow on how to upload a file to Android from a PC/another Android device??
Thx for listening. :)

@ phenning
BTW, I've had a try "Playing audio file remotely" using Automagic's HttpRequest and accomplished to trigger/execute (and stop) an MP3 file on my Android phone from a browser (iPad, PC) without a problem (flow attached). And yes, you have to change/fix the path to your remote/local file accordingly!

HowTo:
Let's say you wanna start the song/file Alice in Chains - Kashhmir.mp3 on your Android device.
Simply request the file via your browsers address bar (well, using your own IP): 192.168.178.24:8080/automagic/Alice in Chains - Kashmir.mp3
Another filename? Another song will be triggered (if existing on/in the same path/folder). Requesting without a proper filename will stop a running song instantaneously.

PS. Interested to create static HTTP requests using an app? The following app offers to create a list to send this kind of requests: https://play.google.com/store/apps/deta ... _shortcuts
Attachments
RunRemoteMP3.xml
(2.26 KiB) Downloaded 1170 times

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Playing audio file remotely

Post by Desmanto » 13 Mar 2020 19:44

It is weird that I can't find @phenning post now. It seems just vanished. I have seen this kind of disappearing post several times, but I mostly forgot it. Your post is the proof that you have read phenning's post before it disappear. Maybe forum's problem?

@phenning : Thanks to your simple html which host the mp3 and you say you can play the music directly using google play music. I have tested it out, and we don't need 3rd party app to play the sound. Simply put the url link to your remote webserver in the action "sound". Something like

Code: Select all

http://192.168.1.123/mp3/song.mp3
Automagic will download the file and play (stream) the mp3 immediately, much better. To stop the song, use stop action sound.

But if you need to use 3rd party app, such as play music, you can still stop the sound using action Control Audio Player, choose Media Button Stop, send to specified app, pick play music

However using sound to play remote url file will always redownload the file at every play. This will waste your emmc write cycle. So if you need too play the same file again and again, and still want to be able to keep adding file, better instruct the remote client to download the mp3 first, and play it locally. Or you can also upload the file to the remote client, move the file to directory and play it. Upload takes much more config though.



@BoBo : I learnt so many things this week. I just discovered my phone support ramdrive all the time using tmpfs created by default in /storage/self. I now have temporary super high speed disposable space to process my temporary file. This ramdrive can be used to hold the temporary stream mp3 file without reducing my emmc write cycle. I have to modify a lot of my "PC link" flows to use this RAM drive instead. Copying and processing temporary file will be much easier then.

Back to your topic, playing audio file remotely. You don't need any other app to do it, Automagic can do it all. Now let's give name to each device.

Device A, your phone. it has the mp3 file, it has Automagic and can send the file to the remote device
Device B, your tablet. It is passive, it has automagic, the trigger HTTP request should be enabled in all method and waiting command from the phone A.

There are several methods to do it.
1. Stream method
The same as phenning method above.
Phone A : act as webserver, Automagic Http request trigger enabled. Add Action write HTTP Response file, point to your mp3, example song1. To have multiple files choices, you need to create map object to store the naming. But let's leave that first and use only single file.
Tablet B : act as webserver too, but only to receive command. HTTP request trigger enabled and action Sound.

Phone A then use another flow to use HTTP request to Tablet B IP, example http://192.168.101:8080/automagic/playsong1. Tablet B react to this command, take the playsong1 command and use action Sound to play the remote file at phone A, example http://192.168.1.100:8080/mp3/song1. Phone A react back to this sound action and give the mp3 stream of song1. (remeber to encodeurl if url has space or special char).

Phone A can use another command using HTTP request to Tablet B, http://192.168.101:8080/automagic/stop. Tablet B react and use stop action sound, which stop playing the sound.

This method require Phone A to act as webserver too. And the downside is tablet B will always redownload the song at every play, wasting bandwidth and reduce the tablet's emmc lifespan. Use this method only if you play different file everytime. I don't recommend this method.

2. Download method
Similar to 1. Stream method. But Tablet B don't use action sound directly. It first check to the song folder in the tablet, example exists("/sdcard/Automagic/song/song1.mp3"), if it already has the song1 file, it directly use action sound to play. But if not, then it use Download files to download from Phone A, store it in the song folders as song1, then use action sound to play it.

This method still require phone A to act as webserver too. It only download the song if it doesn't have the song yet. This will save bandwidth and reduce unnecessary emmc write. But the tablet memory will keep filled up.

3. Upload method
This method is different that 1 and 2.
Phone A : doesn't need webserver. It only has to have the files.
Tablet B : still have the webserver standby

Phone A use HTTP request to Tablet B. Tablet B check if already have the file, directly play it. If not, then it response to Phone A, it doesn't have the file yet. Phone A continue the flow and use HTTP reqeust again, use POST method, Content Type : Form Data File Upload, choose the mp3 to upload. At the Tablet B, it will receive the file as temporary name, store in the path of variable {file_upload_field}. Rename the file to {http_params} (real file name from phone A). Then use action sound to play the file.

This method has the plus side that Phone A now doesn't have to enable the web server anymore. It only need to send the request and upload the file. I prefer this method, but it need more configuration than other method.

4. Upload method with FTP
This is similar to 3rd one, but it require the tablet to have FTP server. MiXplorer can create FTP server with password. It is redundant compared to method 3, but maybe you already have FTP server always enabled on the tablet.

Same as method 3, but instead of HTTP request using upload method, you use action FTP upload and you can copy directly to the proper path, You don't have to deal with the http params anymore.

This method has downside of additional FTP server, which might not be suitable if you want to keep the resource at minimum.

PC version.
With PC, windows or linux, you can use binary curl to post the request or upload the file. For Windows, you can use eventghost with python script to send the request or upload file, just like what I am using. That's why I need temporary storage path to save these kind of files.

It takes a while to create a proper flow with mutilple files choices and map object. (i only have proof concept with single file). I maybe only can create it tomorrow. So meanwhile, see which method suit you the best. I still prefer method 3 though.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

BoBo
Posts: 129
Joined: 05 May 2014 12:45

Re: Playing audio file remotely

Post by BoBo » 13 Mar 2020 22:05

@Desmanto
Erm, I've to admit that I've created an additional/previous post last night that I've deleted a few hours later bc I thought that the way to execute an HttpRequest via a webpage isn't really interesting (and the way to go). So you've probably confused me with @phenning (the owner of this thread) :oops: Sorry!

And, yeah! Meanwhile, I've changed the flow (that I've attached to the successor of the deleted post) to run the MP3 file directly and locally, means without the Google Music Player (as you've recommended already in your initial/previous post).
Thx 8-)

Currently, I'm looking for a way to create/script a widget that looks like this ...
http://getwallpapers.com/wallpaper/full ... 00-ios.jpg
... so every album/cover art should be linked with its respective folder, and once clicked will trigger a playlist file (m3u/pls) that plays the folders content one by one.
But that's another story (and should be hosted at a separate, means, my own thread/request) ;)

Thx 4 listening and your support. Much appreciated 8-)

PS. JFTR, I use Autohotkey (autohotkey.com) for scripting on Windows.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Playing audio file remotely

Post by Desmanto » 18 Mar 2020 18:34

@Bobo : Sorry too, I read that while working, so might not pay atttention to the poster name properly :D
I also prefer to play locally when possible. The HTTP request just add the possibility to add new song via remote device, needing less config on the server device (tablet).

It is possible to design the widget like. Just add the album picture to the widget. It will be tedious though. And remember widget action limited to max 8x8 cells, so maximum 64 per widget. You can then use widget mapping to play the corresponding folder song : viewtopic.php?f=4&t=8525

I also use autohotkey, but mostly for hotkey mapping. For more automation, I still prefer eventghost. It has the webserver built-in, make it as a perfect combo to marry it with Automagic.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

phenning
Posts: 6
Joined: 18 Dec 2015 04:25

Re: Playing audio file remotely

Post by phenning » 07 Jun 2020 09:23

Thanks a lot for the input.

I have to admit that since March I have been terribly busy by switching my faculty's teaching efforts to online services, so I did not really have time to try these suggestions. Will look into them now.

OK, done, thank you for the help. Since I have to submit the file from one of my SmartHome servers, I use curl there (or rather, curl classes addressing libcurl).
Currently however, Automagic does not store the received file under the name I submitted - but rather as a temporary file in the httpd subfolder of Automagic. This does not constitute a problem, because this random filename is obtained in the Automagic variable file_data, and therefore a simple action can store it in the proper location.

As a suggestion I might add, that the documentation of this trigger could be improved. Neither from the first line of the documentation, nor from the "note" attached as second line one sees that this trigger activates the built-in web server.

Regards

pah

Post Reply