autostart script and how to toggle autonext via script

MOC version: 
2.6-alpha3, Debian 10

Hello all,

first of: praise: NICE JOB! :)

thanks for this nice no gui needed music player :)

the random shuffle function of mocp works perfectly

searching recursively through all subdirs and then playing all songs randomly from all subdirs :)

(VLC has an issue here... it seems not to really to recurse and shuffle, but starts playing with all songs it the top directory)

challenge:

trying to put together a script, that can auto start with the computer (under gnome2 mate desktop this can be nicely done via the gui)

the script used is this:

#!/bin/bash
echo "=== mocp autostart script v1 ==="
echo "quit mocplayer gui with: Shift+Q"
echo "to stop mocp background server: mocp -x"

echo "===== # start background server"
mocp -S

echo "===== # clear the playlist"
mocp -c

echo "===== # modify play settings (shuffle on (jump to next song randomly, autonext (automatically play next song on playlist))"
mocp -t s
mocp -t n <- DOES NOT TOGGLE autonext!?

echo "===== # add first argument to script as music dir"
echo "(depending on the amount of music this could take a while)"
echo "adding dir:" $1 " to playlist"
mocp -a $1

echo "===== # autostart playback"
mocp --play

echo "===== # show gui in xterm (Quit with Shift+Q)"
echo "and change dir to: "$1
xterm -e "mocp -O AutoNext=yes -m $1"

# stop everything
# mocp -x

https://dwaves.de/2020/09/05/gnu-debian-linux-install-and-autostart-play-music-from-command-line-with-mocp-mocplayer-musicplayer-music-on-console-play-music-without-gui-without-desktop-hotkeys-shortcuts/

can not get "autonext" to be on when starting via this script.

also: the songs do not seem to get added to the playlist...

they are on the left side, but not on the right side?

best regards

Why not prepare a fitting config file and just use it with with mocp -C?

AutoNext is by default on, maybe your toggle just disables it? You can also use mocp -O AutoNext=yes

As to the playlist, didn't you by some chance disable SyncPlaylist?

all the user wants is

1) play all songs in directory X

2) start play on startup

3) shuffle on

4) auto next on

5) repeat all on

how would this be done in a one-liner?

How about:

mocp -S && mocp -o r,s,n && mocp -l X/*

Here I've started the MOC Server in background; if you want the Client as well, you can start that separately by appending a '; mocp'. If you do want to start the Client separately, then you may (or may not) want to synchronise the playlist with the Server (the '-y' option). If you start the Server in background, then you will either need to stop it via the commpand line ('mocp -x') or using a started Client keypress ('Q').

It all depends on what it is you're trying to achieve.

thanks for ur reply

so the one-liner in question would be:

mocp -S && mocp -o r,s,n && mocp -l X/* /home/user/Music; mocp;

1) it does not autostart playback

2) shuffle is off? (can be activated manually via Shift+S)

delted the config folder before trying ur one liner rm -rf ~/.moc/

The example I posted would need some tweaking to fit your particular directory layout. Now we know a little more, we can do some of that tweaking:

mocp -S && mocp -o r,s,n && mocp -l /home/user/Music/*; mocp

that works nicely :)

will update the blog post

shuffle ain't active when using this one line

It works for me (and that's genuine, not just a scripted corporate response).

When you say "not active", do you mean not toggled on or toggled on but not actually shuffling?

I also thought you might run into another problem if you have a large number of files and/or long filenames. There is a limit to the length of a command line and you may exceed it.

first of all: absolutely LOVIN' MOCP!

it is now my default (replaced vlc)

exactly! shuffle ain't toggled on when started like this:

/scripts/music.sh /home/user/Music # show script content cat /scripts/music.sh # autoplay with repeat shuffle mocp all music in $1 mocp -S && mocp -o r,s,n && mocp -l $1/*; mocp

it shuffles great, when it shuffles (properly searches and shuffles all music files in all sub directories (which vlc ain't))

lovely piece of open source software!

even when the automated startup is a little complicated :)

Try adding a sleep(1) between the first and second 'mocp', like this:

mocp -S && sleep 5s && mocp -o r,s,n && mocp -l $1/*; mocp

My thinking here is that the server may not have fully started before the settings toggling is attempted.

just tested the one-liner

mocp -S && sleep 5s && mocp -o r,s,n && mocp -l $1/*; mocp

strange enough, repeat and auto next are now toggled on

but shuffle is off? :-O

Okay, this is going to require a little more digging.

What happens if you try this:

mocp -S && mocp -o r,n && mocp -o s && mocp -l $1/*; mocp

when doing

mocp -S && mocp -o r,n && mocp -o s && mocp -l /home/user/Music/*; mocp

shuffle repeat and next are toggled on but when scripted

# script content mocp -S && mocp -o r,n && mocp -o s && mocp -l $1; mocp # called like /scripts/music.sh "/home/user/Music/*"

it ain't workin hm...

Try changing the '$1' to '$@' in your script.

If that works, try returning to a single 'mocp -o r,s,n'.

If it doesn't work, try removing the quotes around the music script parameter when you invoke it: '/scripts/music.sh /home/user/Music/*'.

If it still doesn't work, add the option '--echo-args' to the 'mocp -l ...' (second to last) in the script and let us know the result (from which you can delete the filenames and replace them with a count of filenames shown to save post length and provide privacy).