Streaming audio server with a Raspberry Pi 5 and Mopidy – Never Mind

Well, this is a bummer. The Iris interface on Mopidy is nice, and when I’m doing everything manually, it works fine. BUT, I wanted to do things with scripting. I can somewhat get things to work, but not reliably. So I’m going to give up on Mopidy and go back to MPD (Music Player Demon).

I’d managed to build a little routine that, once an hour, generates a sound file with the current time in it. I copied it to the right place, updated the file cache so that the new file is the current one, and then threw (using CURL) the command to add the file to the Mopidy queue. For testing, I had cron run it every two minutes.

# Add the current_time.mp3 file to the queue

/usr/bin/curl -s -X POST "$MOPIDY_URL" \
-H "Content-Type: application/json" \
-d '{
"method": "core.tracklist.add",
"params": {
"uris": ["'"$FILE_URI"'"],
"at_position": 1
},
"id": 1,
"jsonrpc": "2.0"
}'

But, if the queue is empty, Mopidy isn’t going to play anything. So then I had to add:

# Start playback

/usr/bin/curl -s -X POST "$MOPIDY_URL" \
-H "Content-Type: application/json" \
-d '{
"method": "core.playback.play",
"id": 2,
"jsonrpc": "2.0"
}'

And now I’ve three problems.

The first is that there is a weird loop problem where once: the file plays correctly. I’ll hear “The current time is 16:40.” The next time the cron job runs the bash script, I’ll hear “The current time is 16:42. The current time is 16:42.” The third time it runs, I’ll hear “The current time is 16:44. The current time is 16:44. The curren” and the playback is interrupted.

It is always in triples; 16:46 would play fine, 16:48 would play twice, and 16:50 would attempt to play three times but get cut off.

So that is one problem. The next is that I prefer to do my scripting in Perl, and I know that Perl has been doing JSON-RPC for a really long time now. But the Perl script I wrote doesn’t seem to be connecting to the Mopidy server. It tells me that it connected, and shows me a result (instead of a refusal to connect), but the Mopidy debug log does not acknowledge that a connection was made.

The third is that even when I add a song manually using the Iris interface, that “core.playback.play” method would break the playback of the currently playing song. The idea was that if I only create a current_time.mp3 file at the top of the hour, and add it to the queue, then within a few minutes, I’ll hear was hour it is. But now I’ve got the worst of both worlds: if the queue was empty, no playback of the current_time.mp3, but if I trigger the playback, the current song gets clobbered. Sigh.

I really liked that Mopidy has the nice Iris web client; but, if the only way to interact with the server is via mouse and keyboard, well then I’m out.