rodio icon indicating copy to clipboard operation
rodio copied to clipboard

Panic on "The device doesn't support any format!?: DeviceNotAvailable" when playing sound

Open Restioson opened this issue 5 years ago • 12 comments

Similarly (but not the same afaict) to #130, Rodio panics on this trivial example:

if let Some(device) = rodio::default_output_device() {
    if let Ok(file) = File::open("res/notification_sound_clearly.ogg") {
        if let Ok(src) = rodio::Decoder::new(BufReader::new(file)) {
            rodio::play_raw(&device, src.convert_samples());
        }
    }
}

with the following message:

ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
thread 'main' panicked at 'The device doesn't support any format!?: DeviceNotAvailable', /home/restioson/.cargo/registry/src/github.com-1ecc6299db9ec823/rodio-0.10.0/src/engine.rs:147:30
stack backtrace:

I am on Pop_OS! latest release (Linux/GNOME).

Perhaps my system is misconfigured, but it should still probably not panic, and rather return an error.

Restioson avatar Feb 13 '20 18:02 Restioson

I had a different error, but it resulted in the same panic: The device doesn't support any format!?: DeviceNotAvailable.

For me the problem was that I was running the application as root. My PulseAudio instance runs in user mode (default), and the root user does not have a running instance. Running the application as current user, or starting an audio server for root solved it. This might be relevant for you as well.

Here's my complete log:

ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2564:(snd_pcm_open_noupdate) Unknown PCM default
thread 'main' panicked at 'The device doesn't support any format!?: DeviceNotAvailable', src/libcore/result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

timvisee avatar Feb 27 '20 15:02 timvisee

I believe it was user mode but I'm not sure. I will try it again. I think in the end I switched to some other crate that worked correctly. Thanks!

Restioson avatar Feb 28 '20 08:02 Restioson

I get similar error running basic.rs on Arch:

connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
thread 'main' panicked at 'The device doesn't support any format!?: DeviceNotAvailable', src/engine.rs:151:30

I am using pulseaudio and sound works in Chrome/Firefox

koalefant avatar Apr 13 '20 19:04 koalefant

@koalefant it's trying to connect to jack, is this what you intended?

richard-uk1 avatar Jul 13 '20 13:07 richard-uk1

@koalefant it's trying to connect to jack, is this what you intended?

Not at all. It detects it as default device and crashes. Althought other applications work fine through Pulse. I wrote a code as a workaround that first tries a device with name "pulse" and then falls back to default device.

Unfortunately I had to add explicit dependency on cpal for this to my project.

koalefant avatar Jul 13 '20 15:07 koalefant

I'm having the same issue. In my case it tries ALSA instead of Jack, but I'm still a pulse user

luciusmagn avatar Aug 23 '20 10:08 luciusmagn

Same issue here. @koalefant Could you post your workaround please?

SkyLeite avatar Aug 28 '20 00:08 SkyLeite

@RodrigoLeiteF I use following code, but it is only tested on my machine:

            let available_hosts = cpal::available_hosts();
            let mut pulse_device = None;
            for host_id in available_hosts {
                let host = match cpal::host_from_id(host_id) {
                    Ok(h) => h,
                    Err(_) => continue
                };
                let devices = match host.devices() {
                    Ok(d) => d,
                    Err(_) => continue
                };
                for (_device_index, dev) in devices.enumerate() {
                    if let Ok(dev_name) = dev.name() {
                        if dev_name == "pulse" {
                            pulse_device = Some(dev);
                        }
                    }
                }
            }
            let pulse_output = pulse_device.as_ref().map(|d| rodio::OutputStream::try_from_device(d).ok()).flatten();
            let output = pulse_output.or_else(|| rodio::OutputStream::try_default().ok());

koalefant avatar Aug 28 '20 20:08 koalefant

Is there a priority for different audio servers? My setup keeps trying to use alsa while pulseaudio is running. I think it's always preferable to use an audio service that supports multiple outputs first: pulseaudio, jack, oss, sndio, etc. Strangest to me is that it sometimes will work while seemingly nothing has changed (got water, came back, etc)

sburris0 avatar Jan 20 '21 02:01 sburris0

(caveat: this might not be correct) I think work on rodio predates different hosts in cpal. It might just be a case of forwarding the host enumeration/selection options from cpal into rodio?

richard-uk1 avatar Jan 20 '21 15:01 richard-uk1

Same issue. I didn't feel comfortable even trying to start a sound server for root, so instead installing https://archlinux.org/packages/extra/x86_64/pulseaudio-alsa/ solved it for me.

Abendstolz avatar Jan 23 '21 14:01 Abendstolz

Same issue but installing pulseaudio-alsa did not solve it for me (I already had it installed, anyway)

slondr avatar Oct 01 '21 01:10 slondr