Play an Audio CD in Terminal
mpv is a great tool to play all sorts of media in the terminal. Let's play an audio CD and groove to our latest mix.
Just works
Get mpv:
sudo apt install mpv
This may just work for you (hopefully). Insert your CD, and run:
mpv cdda://
If this works, great. Party on!
Btw, the cdda://
is kind of like a protocol. It's not a specific file. Instead, it's telling mpv where to look for a file to play.
Bonus: Play a specific track with mpv cdda://2
(for track 2).
If this doesn't play, there may be a little more to do. Read on.
Test Sound
Make sure that sound is coming out of your speakers:
speaker-test -t wave -c 2
If this works, you should hear a human voice announce speaker output.
Detect Audio CD
Another basic: Make sure that the audio CD is present. Run:
cdparanoia -Q
A CD present will yield a track listing:
cdparanoia III release 10.2 (September 11, 2008)
Table of contents (audio tracks only):
track length begin copy pre ch
===========================================================
1. 118403 [26:18.53] 0 [00:00.00] no no 2
2. 130700 [29:02.50] 118403 [26:18.53] no no 2
TOTAL 249103 [55:21.28] (audio only)
Troubleshoot Audio Output
For several iterations, I couldn't get my mpv
command to work. I'd mostly get issues reported like this when using the mpv -v
(for verbose) flag:
...
[ao/alsa] opening device 'default'
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused
[ao/alsa] Playback open error: Connection refused
[ao] Failed to initialize audio driver 'alsa'
[cplayer] Could not open/initialize audio device -> no sound.
...
Ok, maybe I need to switch devices.
To see the audio output devices available, run:
aplay -l
And see something like:
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC256 Analog [ALC256 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
...
This first device looked right. I added a few more output flags to the mpv
command:
mpv cdda:// --cdrom-device=/dev/sr0 -v -ao=alsa --audio-device=alsa/hw:0,0
-ao
specifies the audio output driver. You can see the options available using mpv --ao=help
. Also is the lowest- (kernel-) level driver. I used it, but your mileage may vary.
Just specifying the output driver wasn't enough for me intially, though. I had to specify the device itself, hence the --audio-device
flag. Now that this uses hw:0,0
, hardward device 0, subdevice 0. I don't know why I had to be that painfully specific.
But after it worked once with all that jazz, the normie mode worked as well:
mpv cdda://