use std::{error::Error, fmt::Display, time::Duration};
use symphonia_core::errors::Error as SymphError;
#[non_exhaustive]
#[derive(Debug)]
pub enum AudioStreamError {
RetryIn(Duration),
Fail(Box<dyn Error + Send + Sync>),
Unsupported,
}
impl Display for AudioStreamError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("failed to create audio: ")?;
match self {
Self::RetryIn(t) => f.write_fmt(format_args!("retry in {:.2}s", t.as_secs_f32())),
Self::Fail(why) => f.write_fmt(format_args!("{why}")),
Self::Unsupported => f.write_str("operation was not supported"),
}
}
}
impl Error for AudioStreamError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum MakePlayableError {
Create(AudioStreamError),
Parse(SymphError),
Panicked,
}
impl Display for MakePlayableError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("failed to make track playable: ")?;
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::Panicked => f.write_str("panic during blocking I/O in parse"),
}
}
}
impl Error for MakePlayableError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}
impl From<AudioStreamError> for MakePlayableError {
fn from(val: AudioStreamError) -> Self {
Self::Create(val)
}
}
impl From<SymphError> for MakePlayableError {
fn from(val: SymphError) -> Self {
Self::Parse(val)
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum MetadataError {
NotLive,
NotParsed,
}
impl Display for MetadataError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("failed to get metadata: ")?;
match self {
Self::NotLive => f.write_str("the input is not live, and hasn't been parsed"),
Self::NotParsed => f.write_str("the input is live but hasn't been parsed"),
}
}
}
impl Error for MetadataError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum AuxMetadataError {
NoCompose,
Retrieve(AudioStreamError),
}
impl Display for AuxMetadataError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("failed to get aux_metadata: ")?;
match self {
Self::NoCompose => f.write_str("the input has no Compose object"),
Self::Retrieve(e) => f.write_fmt(format_args!("aux_metadata error from Compose: {e}")),
}
}
}
impl Error for AuxMetadataError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}
impl From<AudioStreamError> for AuxMetadataError {
fn from(val: AudioStreamError) -> Self {
Self::Retrieve(val)
}
}