I am trying to play an mp3 from the rpi where OH also runs.
I have seen that I can run some commands on the rpi terminal like
wget www.website.com/track1.mp3
mpg321 track1.mp3
and this will play the .mp3 track fine.
Does anyone know if i can execute these commands automatically using the Exec binding and then once I have finished playing the track execute a rm track1.mp3 command to delete it from the directory where i downloaded it.
maybe someone else as i am a beginner, too.
But i think in your case you donât need the exec binding if you are already inside of a rule - executeCommandLine should be fine.
Yes, I recommend using executeCommandLine inside a rule rather than using the Exec binding. However, you donât really need to write an external script for this. Just run several executeCommandLines.
var String results = executeCommandLine("wget " + url + mp3, 5000)
logInfo("Exec", results)
results = executeCommandLine("mpg321 " + mp3, 20000) // make timeout longer than longest mp3 you would ever play
logInfo("Exec", results)
results = executeCommandLine("rm " + mp3, 5000)
logInfo("Exec", results)
Great thank you so much this is exactly what i need as my current solution was to have a separate xbmc image on a separate rpi and then issue commands from there to play a .mp4 file online. At least now I can download the next (preemptive) track and play it from the same rpi where OH is running. PERFECT.
@rlkoshak Is it possible to do a wget command while the track is playing from mpg321 /path/track1.mp3?
I thought i would share here so others can benefit from this solution.
I create a node.js program (that will run on the same rpi as OH) that will listen to a mqtt channel for a track Url. The program will the play the track using the player plugin (https://www.npmjs.com/package/player)
The OH rule will be the âcontrollerâ publishing track urlâs and commands (i.e. play and pause) to the mqtt channel.
The Node.js program will be subscribed to the mqtt channel and will respond accordingly.
Since MQTT is quick there should be no delay in the node.js responding asynchronously. There will no need to delete the track as it is streamed via the player plugin for node.js.