Android: pcm_open failed cannot open device '/

2019-08-08 00:10发布

问题:

A custom piece of hardware is running Android with the audio drivers installed.

An simple Android app is created to play some audio using media player, the app is tested on a emulator so it works for sure.

When running the device on the hardware, error message from logcat displays the following many times:

01-01 01:09:16.355    2792-3186/? E/audio_hw_primary﹕ pcm_open(PCM_CARD) failed: cannot open device '/dev/snd/pcmC0D1p': No such file or directory
01-01 01:09:16.375    2792-3186/? E/audio_hw_primary﹕ pcm_open(PCM_CARD) failed: cannot open device '/dev/snd/pcmC0D1p': No such file or directory
01-01 01:09:16.435     2792-375/? E/AudioSink﹕ received unknown event type: 1 inside CallbackWrapper !

under /dev/snd/ there are

controlC0
pcmC0D0c
pcmC0D0p
timer

I am able to play system notifications without any problem. I could also hack the problem by creating a symbolic link pcmC0D1p pointing to pcmC0D0p, and it works. Why is android trying to play non-system sound track on pcmC0D1p? Who is controlling which output it goes to?

回答1:

pcmC0D1p means :

pcm
Card 0
Device 1
Capture/Playback p

Clearly, whatever the node your app is accessing is not present as seen through your ls /dev/snd/.

Normally, if you are playing non-standard sounds like mp3 files, writing to AudioTrack, will handle everything.

If you see only one playback node by doing ls /dev/snd, it means you have only one playback node present, which I think (not sure though) is occupied for standard android sounds.



回答2:

If "pcmC0D1p" device is present in /dev/snd then try to give permission with command

chmod 777 /dev/snd/pcmC0D1p

If it is still not working then this sound card is not available.