Merge pull request #73 from tomaka/example-enumerate

Example enumerate
This commit is contained in:
tomaka 2015-09-22 14:49:31 +02:00
commit debb6c957c
5 changed files with 38 additions and 0 deletions

17
examples/enumerate.rs Normal file
View File

@ -0,0 +1,17 @@
extern crate cpal;
use cpal::*;
fn main() {
let endpoints = cpal::get_endpoints_list();
println!("Endpoints: ");
for (endpoint_index, endpoint) in endpoints.enumerate() {
println!("{}. Endpoint \"{}\" Audio formats: ", endpoint_index + 1, endpoint.get_name());
let formats = endpoint.get_supported_formats_list().unwrap();
for (format_index, format) in formats.enumerate() {
println!("{}.{}. {:?}", endpoint_index + 1, format_index + 1, format);
}
}
}

View File

@ -153,6 +153,11 @@ impl Endpoint {
Ok(output.into_iter())
}
}
#[inline]
pub fn get_name(&self) -> String {
"unknown".to_owned() // TODO:
}
}
pub struct Voice {

View File

@ -105,6 +105,12 @@ impl Endpoint {
{
Ok(SupportedFormatsIterator(try!(self.0.get_supported_formats_list())))
}
/// Returns the name of the endpoint.
#[inline]
pub fn get_name(&self) -> String {
self.0.get_name()
}
}
/// Number of channels.

View File

@ -33,6 +33,11 @@ impl Endpoint {
{
unreachable!()
}
#[inline]
pub fn get_name(&self) -> String {
"null".to_owned()
}
}
pub struct SupportedFormatsIterator;

View File

@ -51,6 +51,11 @@ unsafe impl Send for Endpoint {}
unsafe impl Sync for Endpoint {}
impl Endpoint {
#[inline]
pub fn get_name(&self) -> String {
"unknown".to_owned() // TODO:
}
#[inline]
fn from_immdevice(device: *mut winapi::IMMDevice) -> Endpoint {
Endpoint {