Play music from command line on ubuntu

Terminal

If you are too addicted to the terminal/console and want to use it for every possible thing, then know that it can play music as well. There are many utilities for playing music files like mp3 directly from the commandline. They can be used to browse the file system, select music files and make a playlist. All from inside a terminal.

To get even more power, use a drop down terminal like yakuake or guake so that the terminal wont show up on the desktop.

So lets take a look at the tools that play music from the commandline.

SoX - Sound eXchange, the Swiss Army knife of audio manipulation

Sox is called the swiss army knife of audio manipulation. It can play, convert and apply effects to a variety of audio formats.

Project website
http://sox.sourceforge.net/

Welcome to the home of SoX, the Swiss Army knife of sound processing programs.

SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files, and, as an added bonus, SoX can play and record audio files on most platforms.

Install on Ubuntu

To install sox on ubuntu just use the terminal.

$ sudo apt-get install sox libsox-fmt-all

The libsox-fmt-all package will install the necessary codecs to play formats like mp3.

Play music

Now lets play an mp3 file

$ play lets_rock.mp3 

Dada Bhagwan Na Aseem Jai Jaikar Ho.mp3:

 File Size: 102M      Bit Rate: 8.39k
  Encoding: MPEG audio    Info: 2000
  Channels: 2 @ 16-bit   Track: 1
Samplerate: 44100Hz      Album: Speed Beatz (Disc 1)
Replaygain: off         Artist: Access Music (Am025Q)
  Duration: 27:03:11.55  Title: I CAN SEE CLEARLY NOW (I THINK)

In:0.40% 00:06:34.18 [26:56:37.37] Out:17.4M [  -===|====- ] Hd:3.4 Clip:0

That will start playing the lets_rock.mp3 file right away.

Moc - Music on Console

Moc player is a feature rich music player for the console. It displays a text based file browser where the user can navigate and select the music files to play.

Project website
http://moc.daper.net/

Install on Ubuntu

Install moc from synaptic

$ sudo apt-get install moc

Play music

First launch the moc player by running the "mocp" command in terminal. It will bring up a blue colored file browser. Browse to the directory that contains the music files and hit enter to play.







┌┤...3-4d98-b06f-9dfaebefd6c1/Bhajans├┐┌──────────────┤Playlist├──────────────┐
│../                                  ││                                      │
│music/                               ││                                      │
│1 Access Music (Am025Q) - [62:52|MP3]││                                      │
│1 Access Music (Am025Q) - [     |OGG]││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
│                                     ││                                      │
├────┤Playing...               ├──────────        S.Off 100%  ├───┤>001:02:52├┤
│|| 1 Access Music (Am025Q) - I CAN SEE CLEARLY NOW (I THINK) (Speed Beatz (Di│
│00:03 62:49 [62:52]   44kHz  224kbps [STEREO] [NET] [SHUFFLE] [REPEAT] [NEXT]│
└┤                                                                           ├┘

Moc player supports keyboard shortcuts to control the player. Press S to stop or P to pause. Move back or forward on the tracking by pressing left/right buttons.

Vlc player

The vlc player has an ncurses based commandline interface that can play music from the terminal.

Install vlc player from synaptic

$ sudo apt-get install vlc-nox

Play music

Now start the commandline vlc player by issuing the following command

$ vlc -I ncurses
VLC media player 2.0.5                             

 Source: <no current item>

 [ h for help ]

┌─────────────────────────────────────────────────────────────────────────────┐
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘
┌───────────────────────────────── Playlist ──────────────────────────────────┐
│  Playlist                                                                   │
│  Media Library                                                              │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Now press h for help. It will show all the keyboard shortcuts that can be used to control the player.
The B button will bring up the file browser that can be used to navigate to the media directory and select the file to be player. So navigate to the directory that contains the music files

VLC media player 2.0.5                             

 Source: <no current item>

 [ h for help ]

┌─────────────────────────────────────────────────────────────────────────────┐
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────── Browse ───────────────────────────────────┐
│ + ..                                                                        │
│ + music                                                                     │
│   happy.mp3                                                                 │
│   happy.ogg                                                                 │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Select the music file and hit enter. It will get added to the playlist and the interface would show the playlist.
Now on the playlist select the music file and hit the space bar. It will start playing the music file.

VLC media player 2.0.5                             

 Source   : /home/enlightened/../../m...happy.mp3
 State    : Playing
 Position : 04:01/1:02:52
 Volume   : 100%
┌─────────────────────────────────────────────────────────────────────────────┐
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘
┌───────────────────────────────── Playlist ──────────────────────────────────┐
│  Playlist                                                                   │
│* `-I CAN SEE CLEARLY NOW (I THINK)                                          │
│  Media Library                                                              │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

Control the volumn with a/z keys. Can move backward/forward on the track with left/right or up/down keys as well.
Check the help page for all the supported options.

I noticed that it is bit buggy when pausing/resuming the playback. If the music does not start inspite of the "state" showing as playing then press the up/down or left/right button to shift the playing position. This will start the playback properly.

CMUS - Console Music Player

Cmus is another console based music player.

Project url
http://cmus.sourceforge.net/

Install on Ubuntu

$ sudo apt-get install cmus

Play music

Launch cmus by typing it in the terminal and hit enter. A dull looking interface would come up. Press 5 and the file browser would show. Now browser to the directory containing the media files, select the media file and hit enter. It should start playing.

Press the left/right buttons to move through the track time. Press 7 to see the help page and all the other available options.

To quit, enter ":quit" and hit enter.

Check the tutorial at
https://github.com/cmus/cmus/blob/master/Doc/cmus-tutorial.txt

Last Updated On : 30th May 2013

Subscribe to get updates delivered to your inbox

Leave a comment