have play_once fn and Decoder trait even if decoders are turned off

This commit is contained in:
Andriy S. from cobalt 2017-10-29 21:18:01 +02:00
parent bfad440f6a
commit b14006ec99
2 changed files with 25 additions and 4 deletions

View file

@ -17,8 +17,13 @@ mod wav;
/// Source of audio samples from decoding a file.
///
/// Supports WAV, Vorbis and Flac.
#[cfg(any(feature = "wav", feature = "flac", feature = "vorbis"))]
pub struct Decoder<R>(DecoderImpl<R>) where R: Read + Seek;
#[cfg(not(any(feature = "wav", feature = "flac", feature = "vorbis")))]
pub struct Decoder<R>(::std::marker::PhantomData<R>);
#[cfg(any(feature = "wav", feature = "flac", feature = "vorbis"))]
enum DecoderImpl<R>
where R: Read + Seek
{
@ -66,7 +71,16 @@ impl<R> Decoder<R>
}
}
#[cfg(not(any(feature = "wav", feature = "flac", feature = "vorbis")))]
impl<R> Iterator for Decoder<R>
where R: Read + Seek
{
type Item = i16;
fn next(&mut self) -> Option<i16> { None }
}
#[cfg(any(feature = "wav", feature = "flac", feature = "vorbis"))]
impl<R> Iterator for Decoder<R>
where R: Read + Seek
{
@ -97,6 +111,17 @@ impl<R> Iterator for Decoder<R>
}
}
#[cfg(not(any(feature = "wav", feature = "flac", feature = "vorbis")))]
impl<R> Source for Decoder<R>
where R: Read + Seek
{
fn current_frame_len(&self) -> Option<usize> { Some(0) }
fn channels(&self) -> u16 { 0 }
fn samples_rate(&self) -> u32 { 1 }
fn total_duration(&self) -> Option<Duration> { Some(Duration::default()) }
}
#[cfg(any(feature = "wav", feature = "flac", feature = "vorbis"))]
impl<R> Source for Decoder<R>
where R: Read + Seek
{

View file

@ -97,14 +97,12 @@ extern crate cgmath;
pub use cpal::{Endpoint, default_endpoint, endpoints, get_default_endpoint, get_endpoints_list};
pub use conversions::Sample;
#[cfg(any(feature = "wav", feature = "flac", feature = "vorbis"))]
pub use decoder::Decoder;
pub use engine::play_raw;
pub use sink::Sink;
pub use source::Source;
pub use spatial_sink::SpatialSink;
#[cfg(any(feature = "wav", feature = "flac", feature = "vorbis"))]
use std::io::{Read, Seek};
mod conversions;
@ -113,7 +111,6 @@ mod sink;
mod spatial_sink;
pub mod buffer;
#[cfg(any(feature = "wav", feature = "flac", feature = "vorbis"))]
pub mod decoder;
pub mod dynamic_mixer;
pub mod queue;
@ -121,7 +118,6 @@ pub mod source;
/// Plays a sound once. Returns a `Sink` that can be used to control the sound.
#[inline]
#[cfg(any(feature = "wav", feature = "flac", feature = "vorbis"))]
pub fn play_once<R>(endpoint: &Endpoint, input: R) -> Result<Sink, decoder::DecoderError>
where R: Read + Seek + Send + 'static
{