How can I play a song in the background via my command line?

Solution 1:

Backgrounding play with & fails because play wants to output its status, e.g.

In:12.7% 00:00:27.31 [00:03:07.52] Out:1.20M [!=====|=====!] Hd:0.0 Clip:0  

but cannot if backgrounded. So it keeps waiting until aborted.

To solve this, simply run play with the -q (quiet) switch. This will successfully background it and play will terminate when the song ends.

(sleep 10 ; play -q Desktop/SONGS/01\ -\ Oh\ Baby\ Girl.mp3 ) &

You can stop it by either typing killall play (if no other play instances are running), or by kill $! (if you haven't backgrounded other processes in the same terminal after starting play -- $! gives you the PID of the last backgrounded process)

Solution 2:

there is a better way of running things in the "background" from the command line.

sudo apt-get install tmux

Its one of the most nifty command line programs for Linux. it allows you to have something similar to "tabs in a browser" and switching seamlessly between them without any interruption of running programs. It's not tabs in the terminal program itself though. But within that specific shell you have started.

once install start it by typing

tmux 

in a terminal.

you create new "tabs" with ctrl-A c you switch to next tab with ctrl-A n

here is a more thorough tutorial if you find the man pages hard to understand