Audio in terminal - Debian


16 posts
by Chrunchstick » Tue May 15, 2012 8:07 pm
Hello all,
I have been trying to get audio to work in my Pi. In the GUI everything works now by using:

1. Boot
2. Login
3. run "sudo modprobe snd_bcm2835"
4. startx

I can play music files and sound just works great.
Now my problem. I want to play a music file from the terminal without starting X. I've tried multiple terminal music players (xmms2, mplayer, etc.) and it does not work even when I executed "sudo modprobe snd_bcm2835" right on boot.
On Mplayer i get the following error:

Code: Select all
christiaan@raspberrypi:~$ mplayer Desktop/Hit\ the\ Floor.mp3
MPlayer 1.0rc3-4.4.4 (C) 2000-2009 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing Desktop/Hit the Floor.mp3.
Audio only file format detected.
Clip info:
 Title: Hit the Floor                 
 Artist: Linkin Park                   
 Album: Meteora                       
 Year: 2003
 Comment:                             
 Track: 5
 Genre: Other
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 44100 Hz, 2 ch, s16le, 320.0 kbit/22.68% (ratio: 40000->176400)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
socket(): Address family not supported by protocol
waitpid(): No child processes
AO: [pulse] Init failed: Internal error
Failed to initialize audio driver 'pulse'
[AO_ALSA] alsa-lib: confmisc.c:768:(parse_card) cannot find card '0'
[AO_ALSA] alsa-lib: conf.c:4170:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
[AO_ALSA] alsa-lib: confmisc.c:392:(snd_func_concat) error evaluating strings
[AO_ALSA] alsa-lib: conf.c:4170:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
[AO_ALSA] alsa-lib: confmisc.c:1251:(snd_func_refer) error evaluating name
[AO_ALSA] alsa-lib: conf.c:4170:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
[AO_ALSA] alsa-lib: conf.c:4649:(snd_config_expand) Evaluate error: No such file or directory
[AO_ALSA] alsa-lib: pcm.c:2190:(snd_pcm_open_noupdate) Unknown PCM default
[AO_ALSA] Playback open error: No such file or directory
Failed to initialize audio driver 'alsa'
[AO SDL] Samplerate: 44100Hz Channels: Stereo Format s16le
[AO SDL] using aalib audio driver.
[AO SDL] Unable to open audio: No available audio device
Failed to initialize audio driver 'sdl:aalib'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video


Exiting... (End of file)

It does not matter if I try to play a other music format.
Is there any way I CAN play music files directly form terminal?

Thank you in advance.

Chrunchstick
Posts: 12
Joined: Sat May 12, 2012 12:58 pm
by marcelh18 » Sun May 20, 2012 5:31 pm
Hi :)
For playing music in console you should install a console audio player. I am currently using MOP.
Also keep in mind that sound driver should be loaded before you start the player.
For that, just type "sudo modprobe snd_bcm2835".

Best Regards,
Marcel
Posts: 9
Joined: Sun May 20, 2012 5:27 pm
by Chrunchstick » Sun May 20, 2012 6:53 pm
marcelh18 wrote:Hi :)
For playing music in console you should install a console audio player.


Mplayer is also a console player. I have tried about 6 console players. They all do not work.
Posts: 12
Joined: Sat May 12, 2012 12:58 pm
by bredman » Sun May 20, 2012 7:10 pm
Have you tried the tests in the troubleshooting wiki?
http://elinux.org/R-Pi_Troubleshooting#Sound
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by marcelh18 » Sun May 20, 2012 7:49 pm
Chrunchstick wrote:
marcelh18 wrote:Hi :)
For playing music in console you should install a console audio player.


Mplayer is also a console player. I have tried about 6 console players. They all do not work.


From your error log, it seems that the sound driver is not loaded. Try "lsmod" and reply the result here.
P.S. The player i use is MOC, not MOP. I misstyped in the previous post.
Posts: 9
Joined: Sun May 20, 2012 5:27 pm
by peteshew » Mon May 21, 2012 8:59 am
I have added snd_bcm2835 to the file /etc/modules so that the module gets loaded automatically. I rarely use anything other than SSH at the moment.

I have found mplayer plays for a short while (from a second to up to half a minute) and then stops playing although mplayer is still going.

I installed MPD and MPC which seems to work more reliably e.g. for streaming internet radio.

I installed shairport to act as a remote 'speaker' for iTunes. This runs for maybe ten minutes before sound stops coming out with no error or failure messages.
Posts: 2
Joined: Sun May 20, 2012 8:35 am
by Chrunchstick » Mon May 21, 2012 4:32 pm
Code: Select all
christiaan@raspberrypi:~$ lsmod
Module                  Size  Used by
bnep                    7912  2
rfcomm                 25240  0
bluetooth             118996  10 bnep,rfcomm
fuse                   49036  1
snd_bcm2835            15388  0
snd_pcm                49240  1 snd_bcm2835
snd_seq                35080  0
snd_timer              13560  2 snd_pcm,snd_seq
snd_seq_device          3684  1 snd_seq
snd                    31624  5 snd_bcm2835,snd_pcm,snd_seq,snd_timer,snd_seq_device
snd_page_alloc          2660  1 snd_pcm


snd_bcm2835 seems to be loaded.
Posts: 12
Joined: Sat May 12, 2012 12:58 pm
by paaland » Tue May 22, 2012 6:23 am
omxplayer will play both music and videos accelerated via OpenMax and use the GPU. Prefered player to use both in console and X.

mpd and mpc also works for audio. I use it for webradio myself. There is an excellent iPhone app for controlling it as well.
Dragon 32>BBC Model B>PC>PC>PC>PC>Raspberry PI (circle complete)
User avatar
Posts: 68
Joined: Mon Mar 12, 2012 2:30 pm
Location: Norway
by Chrunchstick » Tue May 22, 2012 9:23 am
paaland wrote:omxplayer will play both music and videos accelerated via OpenMax and use the GPU. Prefered player to use both in console and X.

mpd and mpc also works for audio. I use it for webradio myself. There is an excellent iPhone app for controlling it as well.

As I said, the problem is not mplayer because non of the players works.
So omxplayer also would not work.
Posts: 12
Joined: Sat May 12, 2012 12:58 pm
by Steady_Bear » Tue May 22, 2012 5:50 pm
What are you using to play music under X?
Does mplayer work under X and not the terminal?

What happens when you run alsamixer (assuming it's installed - not sure what mixer kids use these days ;) )? Both under X and a pre-X terminal.

What is the last block of output from dmesg after modprobeing the sound driver?
Run dmesg (have a quick read to spot anything looking wrong), note the number of the last entry, modprobe your driver, run dmesg again and note all the new comments.
Posts: 110
Joined: Sat Jan 14, 2012 12:06 pm
by Dendennis » Thu May 24, 2012 2:25 am
omxplayer plays mp3's perfectly well for me, mplayer only plays a few seconds no matter what.
Posts: 8
Joined: Thu Dec 01, 2011 2:26 am
by maggocnx » Thu Jun 07, 2012 1:45 pm
I also had the problem with

Code: Select all
 cannot find card '0'

for audio playback. After some time i figured out that sound wasn't working cause i was connected with SSH.

Solved the problem with

Code: Select all
sudo chmod 777 /dev/snd/*


Now mpd and shairport are working quite ok.
Posts: 1
Joined: Tue Mar 13, 2012 9:44 am
by boogiefer » Thu Aug 09, 2012 1:11 pm
@Chrunchstick

Did you fixed this problem?
Posts: 6
Joined: Sat Aug 04, 2012 3:25 pm
by boogiefer » Thu Aug 09, 2012 1:45 pm
hi Chrunchstick,

I have the proble same to you,

I found this http://linuxindetails.wordpress.com/201 ... processes/

it's realy useful.
Posts: 6
Joined: Sat Aug 04, 2012 3:25 pm
by Denex » Thu Sep 19, 2013 11:09 am
Instead of calling
Code: Select all
sudo chmod 777 /dev/snd/*

on every boot you can write following udev rule
Code: Select all
KERNEL=="controlC0", SUBSYSTEM=="sound", MODE="0666"
KERNEL=="pcmC0D0p", SUBSYSTEM=="sound", MODE="0666"

And place it in file /etc/udev/rules.d/99-my_sound.rules
Now udev would apply 0666 permissions
Posts: 1
Joined: Thu Sep 19, 2013 11:04 am
by lordvlad » Tue Sep 09, 2014 8:36 am
I had the same issue of
cannot find card '0'

issue because i tried to play something from a who wasn't on the 'audio' group.

Code: Select all
usermod -a -G audio <usr>

and an logout - login solved it for me without messing with the system.
Posts: 1
Joined: Tue Sep 09, 2014 8:33 am