Posts: 10
Threads: 3
Joined: Feb 2021
Reputation:
0
03-27-2021, 09:40 PM
Dear all
I am enjoying moode a lot - now I want to go a step further and get the system more integrated into my home automation.
I am looking to a neat way to know at any point in time what moode audio is doing, i.e.
- idle: MPD/airplay/spotify/etc mode with status "stop"
- play: as above, but with the status "play"
Now, in case of MPD is active, I just need to send a GET request to http://moode/engine-mpd.php and parse the JSON output, e.g.
Quote:State: play
Volume: 0
File: http://psn1.prostreaming.net:8095/stream
However, I cannot figure out how to obtain a similar output when I stream through Airplay or Spotify. While I am aware of the limited information when using the other streaming options. I would love to have at least
Quote:State: play (possible?)
Volume: 0
File: http://psn1.prostreaming.net:8095/stream
I think there is http://moode/audioinfo.php providing some of the information but it is not JSON compatible, so I will need different parsing strategies depending from the service (doable but not preferred )
Any other suggestion or could you point me to some docs?
DISCLAIMER: I am not a web programmer, I am sure that interactions done through http://moode/ could be done with GET/POST requests, but how?
Thanks
Max
Posts: 13,438
Threads: 305
Joined: Mar 2018
Reputation:
545
You could try the command API.
https://github.com/moode-player/moode/bl.../setup.txt
To get output from commands you will need to uncomment the statement //echo $result; in file /var/www/command/index.php. See below.
Code: // MPD commands
else {
if (false === ($sock = openMpdSock('localhost', 6600))) {
$msg = 'command/index: Connection to MPD failed';
workerLog($msg);
exit($msg . "\n");
}
else {
sendMpdCmd($sock, $_GET['cmd']);
$result = readMpdResp($sock);
closeMpdSock($sock);
//echo $result;
}
Posts: 10
Threads: 3
Joined: Feb 2021
Reputation:
0
(03-27-2021, 10:18 PM)Tim Curtis Wrote: You could try the command API.
https://github.com/moode-player/moode/bl.../setup.txt
To get output from commands you will need to uncomment the statement //echo $result; in file /var/www/command/index.php. See below.
Code: // MPD commands
else {
if (false === ($sock = openMpdSock('localhost', 6600))) {
$msg = 'command/index: Connection to MPD failed';
workerLog($msg);
exit($msg . "\n");
}
else {
sendMpdCmd($sock, $_GET['cmd']);
$result = readMpdResp($sock);
closeMpdSock($sock);
//echo $result;
}
Thanks @ Tim Curtis , I will try it.
Max
Posts: 434
Threads: 10
Joined: Apr 2018
Reputation:
28
03-28-2021, 10:03 AM
(This post was last modified: 03-28-2021, 10:08 AM by adrii.)
Hi didomax
I have a program that needs to determine play/pause/stop state. I use the /var/local/www/currentsong.txt file (enable the Moode metadata file in the UI) with the following logic
https://github.com/antiprism/mpd_oled/bl...s.cpp#L353
If the file doesn't contain "title=something" then a non-MPD player is being used and the state is 'play',
otherwise, if the file includes "state=stop" then the state is 'stop',
otherwise the state is 'play'.
[Seems like there is no longer any detection of 'pause', whatever 'pause' means...]
Adrian.
Posts: 434
Threads: 10
Joined: Apr 2018
Reputation:
28
Hi didomax
Correction: the state will have been previous read from MPD first, and may be 'pause', and so will only be finally be set to 'play' if MPD does not report a status.
Clarification: for the non-MPD players the actual play state is unknown and is simply set to play.
Adrian.
Posts: 10
Threads: 3
Joined: Feb 2021
Reputation:
0
(03-28-2021, 10:19 AM)adrii Wrote: Hi didomax
Correction: the state will have been previous read from MPD first, and may be 'pause', and so will only be finally be set to 'play' if MPD does not report a status.
Clarification: for the non-MPD players the actual play state is unknown and is simply set to play.
Adrian.
Hi @ adrii
Thanks a lot, this goes exactly in the right direction!
The only missing step is the availability of such file through a GET call: does anybody know if there is a way to make these data available through the command API?
Thanks
Max
Posts: 6,028
Threads: 177
Joined: Apr 2018
Reputation:
235
(03-28-2021, 07:07 PM)didomax Wrote: (03-28-2021, 10:19 AM)adrii Wrote: Hi didomax
Correction: the state will have been previous read from MPD first, and may be 'pause', and so will only be finally be set to 'play' if MPD does not report a status.
Clarification: for the non-MPD players the actual play state is unknown and is simply set to play.
Adrian.
Hi @adrii
Thanks a lot, this goes exactly in the right direction!
The only missing step is the availability of such file through a GET call: does anybody know if there is a way to make these data available through the command API?
Thanks
Max
Well, if you want to try a "heat it and beat it" approach (a phrase I learned from a master welder), just create a symlink to make /var/local/www/currentsong.txt visible to the nginx server. Let's abuse the fact that it can serve up imagery for coverart
Code: sudo ln -s /var/local/www/currentsong.txt /var/local/www/imagesw/currentsong.txt
Now point your code to
Code: http://moode.local/imagesw/currentsong.txt
Assuming you've enabled moOde's Metadata file setting under m>Sys config>Local services, you'll see the last written content.
Here, for example, is what is displayed in my web browser while a track is streaming from another moOde player's DLNA server (in this case with BubbleUPnP on my phone as the UPnP control point).
Code: file=http://192.168.4.26:8200/MediaItems/8321.flac
artist=Miles Davis & Quincy Jones
album=Miles & Quincy Live at Montreux
title=Boblicity
coverurl=
track=2
date=1993
composer=
encoded=VBR
bitrate=758 kbps
outrate=16 bit, 44.1 kHz, Stereo, 1.411 Mbps
volume=57
mute=0
state=play
Regards,
Kent
Posts: 10
Threads: 3
Joined: Feb 2021
Reputation:
0
(03-28-2021, 07:51 PM)TheOldPresbyope Wrote: (03-28-2021, 07:07 PM)didomax Wrote: (03-28-2021, 10:19 AM)adrii Wrote: Hi didomax
Correction: the state will have been previous read from MPD first, and may be 'pause', and so will only be finally be set to 'play' if MPD does not report a status.
Clarification: for the non-MPD players the actual play state is unknown and is simply set to play.
Adrian.
Hi @adrii
Thanks a lot, this goes exactly in the right direction!
The only missing step is the availability of such file through a GET call: does anybody know if there is a way to make these data available through the command API?
Thanks
Max
Well, if you want to try a "heat it and beat it" approach (a phrase I learned from a master welder), just create a symlink to make /var/local/www/currentsong.txt visible to the nginx server. Let's abuse the fact that it can serve up imagery for coverart
Code: sudo ln -s /var/local/www/currentsong.txt /var/local/www/imagesw/currentsong.txt
Now point your code to
Code: http://moode.local/imagesw/currentsong.txt
Assuming you've enabled moOde's Metadata file setting under m>Sys config>Local services, you'll see the last written content.
Here, for example, is what is displayed in my web browser while a track is streaming from another moOde player's DLNA server (in this case with BubbleUPnP on my phone as the UPnP control point).
Code: file=http://192.168.4.26:8200/MediaItems/8321.flac
artist=Miles Davis & Quincy Jones
album=Miles & Quincy Live at Montreux
title=Boblicity
coverurl=
track=2
date=1993
composer=
encoded=VBR
bitrate=758 kbps
outrate=16 bit, 44.1 kHz, Stereo, 1.411 Mbps
volume=57
mute=0
state=play
Regards,
Kent
Kent,
This is great! I am going to try this asap.
The output format is not my preferred (JSON would rock ), but it looks the whole process is doable, with no big mods of the base Moode system (important whenever I will need to restore the system from a HW failure ).
I will post the results once available.
Max
|