Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have installed play :

sudo apt-get install sox libsox-fmt-mp3

I can now play my audio files like this :

play Desktop/SONGS/01\ -\ Oh\ Baby\ Girl.mp3

Since I'm learning shell, I wish I could do something like this :

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

After 10 sec's, I can see the screen as :

 File Size: 7.38M     Bit Rate: 260k
  Encoding: MPEG audio    Info: 2012
  Channels: 2 @ 16-bit   Track: 01/09
Samplerate: 44100Hz      Album: Maalai Pozhudhin Mayakathilaey :::tunesinn.blogspot.com:::
Replaygain: off         Artist: Hemachandra, Achu
  Duration: 00:03:46.98  Title: Oh Baby Girl

But the song is not playing. But if I do this (without &) :

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

Is working as expected. But I couldn't able to use my terminal in meanwhile.

How could I resolve my problem, with using &?

share|improve this question
4  
If you only want a CLI player so that you can play audio in the background, I would highly recommend you to try cmus. It even has a script cmuscrobbler for last.fm and you can map global hotkeys in X window system via cmus-remote. Or you could try using an utility like screen. –  jeremija Aug 15 '12 at 8:43
    
cmus is a great program- I should expand this comment into a full answer! –  user76204 Aug 15 '12 at 12:59

4 Answers 4

up vote 8 down vote accepted

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)

share|improve this answer
    
This works. But how come now I stop playing the song? –  Ant's Aug 15 '12 at 9:12
2  
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) –  izx Aug 15 '12 at 9:31

I use

cvlc --play-and-exit "$filename" &>/dev/null &

vlc is pretty ubiquitous.

share|improve this answer

My Nautilus-Actions to add "Play" and "Stop" to the context menu for audio files

To Add Play...

Define a new action as follows

"Action Tab"

  1. Checkbox Ticked for "Display item in selection context menu"
  2. New Action Context Label= Play
  3. Tooltip= Play Audio
  4. Icon= media-playback-start

"Command Tab"

  1. Label= Play
  2. Path= /usr/bin/play -q
  3. Parameters= %f
  4. (Optional W/Effects) Parameters= %f rate -v vol .25 bass +5 treble +5 reverb
  5. Working Directory= %d

"Execution Tab"

  1. Checkbox Ticked for "Normal"

"Mimetypes Tab"

  1. Add audio/mpeg
  2. Add audio/flac
  3. Add audio/x-wav

Or add more if needed or leave it alone to show up everywhere.

The rest can be left alone.


To Add Stop...

Define a new action as follows

"Action Tab"

  1. Checkbox Ticked for "Display item in selection context menu"
  2. Context Label= Stop
  3. Tooltip= Stop Audio
  4. Icon= media-playback-stop

"Command Tab"

  1. Label= Stop
  2. Path= killall
  3. Parameters= play
  4. Working Directory= %d

"Execution Tab"

  1. Checkbox Ticked for "Normal"

"Mimetypes Tab"

  1. Add audio/mpeg
  2. Add audio/flac
  3. Add audio/x-wav

Or add more if needed or leave it alone to show up everywhere.

The rest can be left alone.

share|improve this answer
    
Adjust as needed. Play with the effects options, see the sox manpage for more on that... manpages.ubuntu.com/manpages/raring/en/man1/sox.1.html –  tufkab Jun 20 '13 at 23:10
    
How does this answer the question regarding running this from the command line? Your answer seems to be about Nautilus, a GUI-enabled file manager. It's a nice answer, but for a different question. –  gertvdijk Jun 20 '13 at 23:11
    
Because its a quick and cool way to do this even though its not a command line answer. Couldn't find a question to fit the answer in this case. –  tufkab Jun 20 '13 at 23:15

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

sudo apt-get install screen

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

once install start it by typing

screen 

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.