rodio
rodio copied to clipboard
Panic on "The device doesn't support any format!?: DeviceNotAvailable" when playing sound
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.
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.
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!
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 it's trying to connect to jack, is this what you intended?
@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.
I'm having the same issue. In my case it tries ALSA instead of Jack, but I'm still a pulse user
Same issue here. @koalefant Could you post your workaround please?
@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());
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)
(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?
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.
Same issue but installing pulseaudio-alsa did not solve it for me (I already had it installed, anyway)