Mplayer: Play Audio CD Using Linux Command Line

by on September 14, 2010 · 4 comments· LAST UPDATED September 15, 2010

in

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.

Syntax

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
cdrom="/dev/sr0"
# cache setting
cache=5000
# set audio driver
ao=alsa

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:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 4 comments… read them below or add one }

1 Richard September 30, 2010 at 9:29 am

Or you can just use Herrie as an excellent command line audio player – http://herrie.info/
I use it an awful lot and it has a very small memory and processor footprint.

Reply

2 carlos December 24, 2010 at 11:44 am

Thank you very much for this useful post and for you blog.

Reply

3 Andriy March 21, 2011 at 7:01 pm

Setting ‘cache=5000′ for all files played (i.e, setting it in the configfile) have side effects. In my case it was some mp4-coded videos choppy playback.

Reply

4 Robinson Grullon November 24, 2012 at 10:43 pm

Thank you very much endee, this was a very useful howto. I hope you keep on doing this kind of contribution to the new users. Congratulations!!! God bless you. Sincerely.

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: