Sphaso
Posts: 3
Joined: Wed Dec 19, 2012 9:53 pm

Omxplayer to play a list of files sans GUI

Thu Dec 20, 2012 9:34 am

I want my Raspy to play a series of audio files in a playlist of my choice without using any GUI nor starting X for that matter.

So what do I do?

1) I have an NFS shared folder with all my music
2) I cd into the folder and punch in

Code: Select all

find | grep 'flac\|ogg\|mp3' > playlist.pls
to save all the relative paths to my audio files.

3) then I write a simple script in order to select just the stuff I want to listen to based on a keyword:

Code: Select all

#!/bin/bash

while read line
do
if [[ "$line" == *"$1"* ]]
then
omxplayer \"$line\"
fi
done < playlist.pls
which works something like:

Code: Select all

./playMe "Segovia"
Except it doesn't work :( Omxplayer just whishes me a good day (thank you) for each entry the script can find but it's not streaming any audio. And yes, it plays fine on single files with just a "omxplayer $PATH". And yes, http://www.insideelectronics.co.uk/tag/ ... omxplayer/ this guy says it's possible.

Any idea?
Thank you :)

Knight4
Posts: 10
Joined: Wed Dec 26, 2012 5:27 pm

Re: Omxplayer to play a list of files sans GUI

Wed Dec 26, 2012 5:29 pm

Did you manage to solve the issue? I was looking for that as well.

Sphaso
Posts: 3
Joined: Wed Dec 19, 2012 9:53 pm

Re: Omxplayer to play a list of files sans GUI

Fri Dec 28, 2012 7:21 pm

Unfortunately I have not, I tried different workarounds without success (sleep, grepping ps ax...). I think the best approach at this point would be to modify the omxplayer sources to allow such an option :cry:

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England

Re: Omxplayer to play a list of files sans GUI

Mon Dec 31, 2012 6:57 pm

Have you tried alternative players?

VLC can run in command line mode:-
cvlc MusicFile.mp3

Although the command line player "randomplay" is designed to randomise your playlist, it does have a --norandom option.

mpg123 is another command line player, but I think this only plays mp3 files.

Knight4
Posts: 10
Joined: Wed Dec 26, 2012 5:27 pm

Re: Omxplayer to play a list of files sans GUI

Mon Dec 31, 2012 7:02 pm

AFAIK omxplayer is the only player that can take advantage of the GPU and, in my particular case, I've got some heavy-duty 1080p videos to play... :(

Sphaso
Posts: 3
Joined: Wed Dec 19, 2012 9:53 pm

Re: Omxplayer to play a list of files sans GUI

Mon Dec 31, 2012 8:31 pm

Thanks SteveDee! I'll certainly look into that :)

tiger12506
Posts: 1
Joined: Sun May 05, 2013 3:47 am

Re: Omxplayer to play a list of files sans GUI

Sun May 05, 2013 3:49 am

Old thread, but for those who are looking for it:

Code: Select all

#!/bin/bash

PLAYER="omxplayer -o hdmi"
PLAYLIST="play.pls"

# Play arguments on command line if they exist
if [ $# -ne 0 ]
then
    for file
    do
        $PLAYER "$file"
    done
    exit
fi

# Play the playlist if it exists
if [ -e "$PLAYLIST" ]
then
    IFS=$'\012'
    for file in $(cat "$PLAYLIST")
    do
        $PLAYER "$file"
    done

# Play the directory structure otherwise
else
    for file in *
    do
       $PLAYER "$file"
    done
fi 


Knight4
Posts: 10
Joined: Wed Dec 26, 2012 5:27 pm

Re: Omxplayer to play a list of files sans GUI

Sun May 05, 2013 2:20 pm

tiger12506 wrote:Old thread, but for those who are looking for it:

Code: Select all

#!/bin/bash

PLAYER="omxplayer -o hdmi"
PLAYLIST="play.pls"

# Play arguments on command line if they exist
if [ $# -ne 0 ]
then
    for file
    do
        $PLAYER "$file"
    done
    exit
fi

# Play the playlist if it exists
if [ -e "$PLAYLIST" ]
then
    IFS=$'\012'
    for file in $(cat "$PLAYLIST")
    do
        $PLAYER "$file"
    done

# Play the directory structure otherwise
else
    for file in *
    do
       $PLAYER "$file"
    done
fi 

Thanks! ;)

chlacaux
Posts: 2
Joined: Tue Nov 11, 2014 9:31 pm

Re: Omxplayer to play a list of files sans GUI

Tue Nov 11, 2014 10:10 pm

Hello,
Thank you for the script, but I have a problem with the playlist. What should be the format ?
I've put some echo's on the script to try to understand what is the problem, but I can't see the mistake?
When I use the following script named read_playlist.sh

Code: Select all

    #!/bin/bash

    PLAYER="omxplayer -o hdmi"
    PLAYLIST="play.lst"
 
    # Play the playlist if it exists
    if [ -e "$PLAYLIST" ]
    then
        IFS=$'\012'
	echo "lecture de la playlist : " "$PLAYLIST"
        for file in $(cat "$PLAYLIST")
        do
#		echo "lecture forcee"
#		omxplayer -o hdmi MPEG4_1280x720.mp4
		echo "fichier : " "$file"
		echo "commande : " $PLAYER "$file"
            $PLAYER "$file"
        done
    fi
when uncommented, the line

Code: Select all

omxplayer -o hdmi MPEG4_1280x720.mp4 
is well executed, the video is outpout on HDMI. The command

Code: Select all

echo "commande : " $PLAYER "$file"
returns the line

Code: Select all

commande :  omxplayer -o hdmi "MPEG4_1280x720.mp4"
But when the command
$PLAYER "$file"
is executed I have the following error :

Code: Select all

./read_play_list.sh: line 28: omxplayer -o hdmi: command not found
as if omxplayer is not known there (but known 2 lines before).
Do you have any idea ?
For now, my play list "play.lst" only contains the following line :
"MPEG4_1280x720.mp4"
Do you have any idea of what's going wrong. Thanks for your help.

chlacaux
Posts: 2
Joined: Tue Nov 11, 2014 9:31 pm

Re: Omxplayer to play a list of files sans GUI

Thu Nov 13, 2014 10:54 pm

I've finally understood the problem. It is the command

Code: Select all

IFS=$'\012'
that corrupt my script. To get the file names from my play list (name could contain spaces), the IFS=$'\012' is needed but before executing the command with omxplayer, I have reset the IFS value to it's default <space><tab><newline> with command IFS=$' \t\n'
so now it's working fine with the script modified like this :

Code: Select all

    #!/bin/bash

    PLAYER="omxplayer -o hdmi "
    PLAYLIST="play.lst"

    # Play arguments on command line if they exist
    if [ $# -ne 0 ]
    then
	echo "fichier passe en argument :" "$file"
        for file
        do
            $PLAYER "$file"
        done
        exit
    fi

    # Play the playlist if it exists
    if [ -e "$PLAYLIST" ]
    then
        IFS=$'\012'	# IFS: Internal field separator ; \12=form feed
#	echo "lecture de la playlist : " "$PLAYLIST"
        for file in $(cat "$PLAYLIST")
        do
	IFS=$' \t\n'
		echo "fichier : " "$file"
		echo "commande : " $PLAYER "$file"
		$PLAYER "$file"
        done

    # Play the directory structure otherwise
    else
       echo "pas d argument"
        for file in *
        do
           $PLAYER "$file"
        done
    fi
I hope this will help other people, because I've spent a couple of hours to understand that :roll:

ARaspberry
Posts: 3
Joined: Fri Jul 29, 2016 10:01 am

Re: Omxplayer to play a list of files sans GUI

Sat Jul 30, 2016 6:05 am

I want to run a list of .mp3 files in the background from ssh.
I should also be able to disconnect from ssh but the music should continue playing (headphone jack).
My original code(4 only 1 file):

Code: Select all

mkfifo fifo
chmod 7777 fifo
omxplayer -o local <mp3> <fifo &
echo -n "." > fifo
This used to work, but for some reason it has stopped working.
1. How can I fix this?
2. How should I change this to play multiple mp3 files in the background(ssh disconnectable)?

mjamesferrero
Posts: 21
Joined: Sat Nov 21, 2015 1:06 am

Re: Omxplayer to play a list of files sans GUI

Thu Jan 19, 2017 9:27 pm

Would there be a way to modify the script to play an array of file names instead of a lst file?

jehutting
Posts: 173
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Omxplayer to play a list of files sans GUI

Sat Jan 21, 2017 6:48 am

Something like this?

Code: Select all

#!/bin/bash
# infinity-looper-2.sh
# Infinite looping script
# J.E.HUTTING 21-JAN-2017

#set -x # expand the commands

# set here the files to play ---------------------------------------------------
FILES=`ls /aragorn/music/singles/T*.mp3`
# ------------------------------------------------------------------------------
#echo $FILES

# who's playing it
OMXPLAYER="omxplayer"

echo "*****INFINITE LOOPING SCRIPT!!!"
echo "*****ABORT WITH CTRL+C"
while true; do
    while true; do
        IFS=$'\n'   # IFS: Internal field separator
        for entry in $FILES
        do
            IFS=$' \t\n'

            # let's play
            echo $entry
            $OMXPLAYER "$entry" > /dev/null
        done
    done
done

Return to “Graphics, sound and multimedia”