Next Song after 3 Minutes?

Hello there,

i am happily using Pi Musicbox on a Raspberry 3 B+ for quite some time.

My wife and I are often hearing music via the Pi Musicbox in our living room. We have a playlist on Spotfiy in which we put our favorite songs together. But she puts those annoying long songs in it and when i put “Warriros of the World” from the band Manowar in our playlist she was mad as well :smiley:

So my question is:
Is it possible to configure the Pi Musicbox in webclient, so that every 3 minutes it changes to the next song?
I think that would be fair for both of us :smile:

Many thanks so far for this awesome MusicBox
Have an awesome day

Can anyone help me with this issue?
It’s christmas soon and i’m pretty sure “Last Christmas” will find its way in the playlist ( 4:27 minutes! ).

If it is possibile to reduce my pain, I will happily pay for a beer or two :slight_smile:

Kind regards!

Last Christmas is a true classic!

There isn’t anything that’ll do what you want and I think it’s a but niche to include in the webclient itself. However, we could probably come up with a small bash script that does this.

Basically something listening for MPD player events (using idle) and when a new song starts playing it sleeps for 3 minutes. When it wakes up again it can request the status, if its the same song (and the elapsed time > 3 mins) it skips. Else it sleeps again for 3-elapsed mins.

Which, having written that out, sounds ripe with bugs. There must be a nicer way!

A bash script that would check if its still the same song sounds like a good idea. I didn’t even thought about it. I already made a backup Image for our Raspberry Pi and would totally try everything out.

If a working solution is found i will show my gratitude :smile:

I don’t really have free time to spend on this stuff right now but I had a quick go. I am not going to spend any more time debugging any problems it has, I would suggest you go ask on a general bash programming forum since there is nothing Mopidy/Pi Musicbox specific about this.

#!/bin/bash

MPC='mpc -p 6600'
PLAY_TIME=180

function get_track
{
    echo $($MPC status --format "%file%" | awk 'NR==1')
}
function get_state
{
    echo $($MPC status | awk 'NR==2')
}
function get_elapsed
{
    echo $(echo $1 | awk '{split($3,t,"[/:]"); print (t[1]*60 + t[2])}')
}

LAST_TRACK=""
while : ; do
    STATE=`get_state`
    echo "state is $STATE"
    if echo $STATE | grep -q "playing" ; then
        CURRENT_TRACK=`get_track`
        if [ "$LAST_TRACK" != "$CURRENT_TRACK" ] ; then
            echo "Now playing -> $CURRENT_TRACK"
            LAST_TRACK=$CURRENT_TRACK
            sleep 5
        else
            ELAPSED=`get_elapsed "$STATE"`
            if [ $ELAPSED -gt $PLAY_TIME ] ; then
                echo "Trigger skip ($ELAPSED)"
                $MPC next
            else
                WAIT_TIME=`expr $PLAY_TIME - $ELAPSED`
                echo "Keep playing for $WAIT_TIME"
                sleep $WAIT_TIME
            fi
        fi
    else
        echo "Waiting for playback to start..."
        $MPC idle player > /dev/null
    fi
done