Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Autoplay after restart - questions.
#1
Aternoon all,

I'm trying to understand how the "Autoplay after start" feature works.  The track that starts playing does not always seem to correspond to what was on the play queue at the point when the player stopped.  My use case involves a script that uses MPC commands to put streams on the playlist in response to button presses, and also involves having the power turned off mid playback when my wife wants to "turn off the radio" by switching it off at the wall.  I've run several tests but have not managed to isolate what "sticks" as the last playing track.

The code that runs is this:

Code:
               $status = getMpdStatus($sock);
               workerLog(print_r($status, true));
               sendMpdCmd($sock, 'playid ' . $status['songid']);
               $resp = readMpdResp($sock);
               workerLog('worker: Auto-playing id (' . $status['songid'] . ')');
The "songid" parameter appears to be a pointer to an entry in an array, which I would have assumed is the contents of the current play queue.  I find however that this isn't always the case.  I manipulate the queue with a bash script that does this:

Code:
        mpc clear
        mpc load Preset1
        mpc play
There are some circumstances where the Autostart matches what the UI shows to be on the queue after running my scripted mpc commands, but other times not.  I think after a clean reboot, what ever is in the songid gets updated, but I'm not 100% sure I've proven that, it is clear though that "mpc load" does not reliably alter the thing songid points at.

So two questions:
  1. What does songid point at and under what conditions does it get updated?
  2. If I wished to always start with the same radio stream after restart regardless of what was playing at shutdown, can I just pass that stream into the sendMpdCmd function somehow instead?
----------------
Robert
Reply
#2
1. What does songid point at and under what conditions does it get updated?

MPD maintains two identifiers (song and songid) for an item in the Queue thats playing or stopped and they are reported in the output of the MPD 'status' command.

Code:
telnet localhost 6600
status

song - indicates the position of the item in the Queue starting from 0. The value changes each time the item assumes a new position in the Queue.
songid is assigned to each item in the Queue starting at 1 and never changes.

2. If I wished to always start with the same radio stream after restart regardless of what was playing at shutdown, can I just pass that stream into the sendMpdCmd function somehow instead?

Not really because MPD playback commands operate on Queue item identifiers, either 'song' or 'pongid'. This means that the playable URL has to be first loaded into the Queue, then its song or songid identifier retrieved and then finally play [song | songid]. Another option is to clear the Queue first then the added item will always be at song = 0 or songid = 1.

To troubleshoot try turning off Autoplay then examine MPD status via telnet while player is running and then after the "turn off radio via the wall switch" followed by power up.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
Ah that's making things clearer. It is reverting to songid 1 in some restarts, and it is pot luck what that might be depending on the playback history of the previous session. I'll do some more controlled tests to work out under what conditions it rests the songid.
----------------
Robert
Reply
#4
Also examine the file /var/lib/mpd/state

MPD saves its state in this file but I'm not sure what events trigger the save. The parameter "current" below refers to the item position in the Queue.

Code:
cat /var/lib/mpd/state | grep "current:"
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#5
Ah, that's the fella... My button script isn't triggering an update of that file. Getting close now. Thanks Tim, I'm sure I've got all the pieces now, just need to put them together.
----------------
Robert
Reply


Forum Jump: