use crate::input::AudioStreamError;
use flume::RecvError;
use std::{
error::Error,
fmt::{Display, Formatter, Result as FmtResult},
sync::Arc,
};
use symphonia_core::errors::Error as SymphoniaError;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum ControlError {
Finished,
InvalidTrackEvent,
Play(PlayError),
Dropped,
}
impl Display for ControlError {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "failed to operate on track (handle): ")?;
match self {
ControlError::Finished => write!(f, "track ended"),
ControlError::InvalidTrackEvent => {
write!(f, "given event listener can't be fired on a track")
},
ControlError::Play(p) => {
write!(f, "i/o request on track failed: {p}")
},
ControlError::Dropped => write!(f, "request was replaced by another of same type"),
}
}
}
impl Error for ControlError {}
impl From<RecvError> for ControlError {
fn from(_: RecvError) -> Self {
ControlError::Dropped
}
}
pub type TrackResult<T> = Result<T, ControlError>;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum PlayError {
Create(Arc<AudioStreamError>),
Parse(Arc<SymphoniaError>),
Decode(Arc<SymphoniaError>),
Seek(Arc<SymphoniaError>),
}
impl Display for PlayError {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.write_str("runtime error while playing track: ")?;
match self {
Self::Create(c) => {
f.write_str("input creation [")?;
f.write_fmt(format_args!("{}", &c))?;
f.write_str("]")
},
Self::Parse(p) => {
f.write_str("parsing formats/codecs [")?;
f.write_fmt(format_args!("{}", &p))?;
f.write_str("]")
},
Self::Decode(d) => {
f.write_str("decoding packets [")?;
f.write_fmt(format_args!("{}", &d))?;
f.write_str("]")
},
Self::Seek(s) => {
f.write_str("seeking along input [")?;
f.write_fmt(format_args!("{}", &s))?;
f.write_str("]")
},
}
}
}
impl Error for PlayError {}