Mplayer: Play Audio CD Using Linux Command Line

Posted on in Categories last updated September 15, 2010

How do I play a music cd using MPlayer command line in Linux?

MPlayer is a free and open source media player which can play physical media such as CDs, DVDs, Video CDs and various music formats using command line options. Mplayer has Compact Disc Digital Audio system (CDDA) support to play entire music / audio cd or specific track.


The syntax is as follows (open the terminal type the command):

mplayer -cdrom-device /dev/cdrom cdda://
mplayer -cdrom-device /dev/sr0 cdda://

Sample outputs:

Fig.01: mplayer in Action
Fig.01: mplayer in Action

Setting CDROM Name

The -cdrom-device option specify the CD-ROM device (default: /dev/cdrom). In this example, /dev/sr0 is my actual DVD / cd player under Linux.

Getting Around Buffering Problem

The audio playback may be interrupted ever few hundred milliseconds. You need to cache or buffer in advance using -cache option as follows:

mplayer -cdrom-device /dev/sr0 cdda:// -cache 5000

How Do I Play Specific Tracks?

To play specific tracks, you need to specify the number. In this example play track # 5:

mplayer -cdrom-device cdda://5 -cache 5000

Sample outputs:

Playing cdda://5.
Found audio CD with 7 tracks.
Cache fill:  0.00% (0 bytes)   
Track 5

Track 5
rawaudio file format detected.
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44100 Hz, 2 ch, s16le, 1411.2 kbit/100.00% (ratio: 176400->176400)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample)

You can play tracks 6 to 13 as follows:

mplayer -cdrom-device cdda://6-13 -cache 5000

Configuring Mplayer

You may want to add all options and parameter in your $HOME/.mplayer/config file, so you don’t have to specify every time. Edit ~/.mplayer/config, enter:
$ vi ~/.mplayer/config
Edit / modify as follows:

# default cdrom
# cache setting
# set audio driver

Save and close the file. Now, you can simply type the following command:
$ mplayer cdda://
$ mplayer cdda://5

Useful Keyboard Shortcuts

Quoting from the mplayer man page:

              <- and -> :  Seek backward/forward 10 seconds.
              up and down : Seek forward/backward 1 minute.
              pgup and pgdown : Seek forward/backward 10 minutes.
              [ and ] : Decrease/increase current playback speed by 10%.
              { and } : Halve/double current playback speed.
              backspace : Reset playback speed to normal.
              < and > : Go backward/forward in the playlist (not for audio cds).
              ENTER : Go forward in the playlist, even over the end.
              HOME and END : next/previous playtree entry in the parent list
              p / SPACE : Pause (pressing again unpauses).
              q / ESC : Stop playing and quit.
              + and - : Adjust audio delay by +/- 0.1 seconds.
              / and * : Decrease/increase volume.
              9 and 0 : Decrease/increase volume.
              ( and ) : Adjust audio balance in favor of left/right channel.
              m :  Mute sound.
              o : Toggle OSD states: none / seek / seek + timer / seek + timer + total time.

Further readings:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

4 comment

Leave a Comment