I will make this answer more general. There are couple of things that one should check if having problems with audio. In no particular order:
Check if it's not PCM sample rate/format problem
Currently RPi ALSA driver has no nmap support. This makes plug ALSA plugin behave badly. This plugin should let you play any PCM format you like converting it if needed. But it is not on RPi. Instead it does report to applications that the format is supported but it fails when it starts playback.
One way to fix this is to turn on mmap emulation using .asoundrc file in your home directory or /etc/asound.conf:
pcm.mmap0 {
type mmap_emul;
slave {
pcm "hw:0,0";
}
}
pcm.!default {
type plug;
slave {
pcm mmap0;
}
}
This one may be your actual problem since some mp3 codecs (for example default on raspbian) produce flating point PCM which is not directly supported by the hardware and has to be changed.
Check if pulseaudio is installed
Pulseaudio is problematic on RPi so I would suggest to deinstall it if you are having sound issues, unless you know what you are doing.
This is the only way I could explain why sound was working before running X but not after.
Check if proper audio output is selected
You can choose one of two audio outputs on RaspberryPi using amixer command. You can use one of three modes: 0=auto, 1=analog, 2=hdmi, like this:
sudo amixer cset numid=3 <n>
where is one of 0,1,2. It defaults to auto which may not actually be what we really want.
NOTE: This one is probably not your case as you did get some sound from aplay. It's just for reference to other having similar problems.
Check if audio module is loaded
Using lsmod
command, you should check if snd-bcm2835 is loaded.
NOTE: This one is probably not your case as you did get some sound from aplay. It's just for reference to other having similar problems.