Skip to content

Commit 739977b

Browse files
committed
add default to Output
1 parent 31c30e5 commit 739977b

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub use cpal::{
171171
mod common;
172172
mod sink;
173173
mod spatial_sink;
174-
#[cfg(all(feature = "playback", feature = "experimental"))]
174+
// #[cfg(all(feature = "playback", feature = "experimental"))]
175175
pub mod speakers;
176176
#[cfg(feature = "playback")]
177177
pub mod stream;

src/microphone/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ where
513513
/// # Ok::<(), Box<dyn std::error::Error>>(())
514514
/// ```
515515
pub fn get_config(&self) -> InputConfig {
516-
self.config.copied().expect("ConfigIsSet")
516+
self.config.expect("ConfigIsSet")
517517
}
518518
}
519519

src/speakers.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ use cpal::{
108108

109109
use crate::{common::assert_error_traits, StreamError};
110110

111+
/// TODO
111112
pub mod builder;
112113
mod config;
113114

@@ -126,6 +127,7 @@ assert_error_traits! {ListError}
126127
#[derive(Clone)]
127128
pub struct Output {
128129
inner: cpal::Device,
130+
default: bool,
129131
}
130132

131133
impl From<Output> for cpal::Device {
@@ -134,6 +136,13 @@ impl From<Output> for cpal::Device {
134136
}
135137
}
136138

139+
impl Output {
140+
/// TODO
141+
pub fn is_default(&self) -> bool {
142+
self.default
143+
}
144+
}
145+
137146
impl fmt::Debug for Output {
138147
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
139148
f.debug_struct("Device")
@@ -151,10 +160,11 @@ impl fmt::Display for Output {
151160
/// Returns a list of available output devices on the system.
152161
pub fn available_outputs() -> Result<Vec<Output>, ListError> {
153162
let host = cpal::default_host();
154-
let devices = host
155-
.output_devices()
156-
.map_err(ListError)?
157-
.map(|dev| Output { inner: dev });
163+
let default = host.default_output_device().map(|d| d.name());
164+
let devices = host.output_devices().map_err(ListError)?.map(|dev| Output {
165+
default: Some(dev.name()) == default,
166+
inner: dev,
167+
});
158168
Ok(devices.collect())
159169
}
160170

src/speakers/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ where
513513
/// # Ok::<(), Box<dyn std::error::Error>>(())
514514
/// ```
515515
pub fn get_config(&self) -> OutputConfig {
516-
self.config.copied().expect("ConfigIsSet")
516+
self.config.expect("ConfigIsSet")
517517
}
518518
}
519519

0 commit comments

Comments
 (0)