sl4f_lib/media_session/
types.rsuse fidl_fuchsia_media_sessions2::{ContentType, Error, PlayerState, PlayerStatus, RepeatMode};
use serde::Serialize;
#[derive(Debug, Serialize)]
pub enum SerializablePlayerState {
Idle = 0,
Playing = 1,
Paused = 2,
Buffering = 3,
Error = 4,
}
impl From<PlayerState> for SerializablePlayerState {
fn from(ps: PlayerState) -> Self {
match ps {
PlayerState::Idle => Self::Idle,
PlayerState::Playing => Self::Playing,
PlayerState::Paused => Self::Paused,
PlayerState::Buffering => Self::Buffering,
PlayerState::Error => Self::Error,
}
}
}
#[derive(Debug, Serialize)]
pub enum SerializableRepeatMode {
Off = 0,
Group = 1,
Single = 2,
}
impl From<RepeatMode> for SerializableRepeatMode {
fn from(m: RepeatMode) -> Self {
match m {
RepeatMode::Off => Self::Off,
RepeatMode::Group => Self::Group,
RepeatMode::Single => Self::Single,
}
}
}
#[derive(Debug, Serialize)]
pub enum SerializableContentType {
Other = 1,
Audio = 2,
Video = 3,
Music = 4,
TvShow = 5,
Movie = 6,
}
impl From<ContentType> for SerializableContentType {
fn from(ct: ContentType) -> Self {
match ct {
ContentType::Other => Self::Other,
ContentType::Audio => Self::Audio,
ContentType::Video => Self::Video,
ContentType::Music => Self::Music,
ContentType::TvShow => Self::TvShow,
ContentType::Movie => Self::Movie,
}
}
}
#[derive(Debug, Serialize)]
pub enum SerializableError {
Other = 1,
}
impl From<Error> for SerializableError {
fn from(e: Error) -> Self {
match e {
Error::Other => Self::Other,
}
}
}
#[derive(Debug, Default, Serialize)]
pub struct PlayerStatusWrapper {
pub duration: Option<i64>,
pub player_state: Option<SerializablePlayerState>,
pub repeat_mode: Option<SerializableRepeatMode>,
pub shuffle_on: Option<bool>,
pub content_type: Option<SerializableContentType>,
pub error: Option<SerializableError>,
pub is_live: Option<bool>,
}
impl From<Option<PlayerStatus>> for PlayerStatusWrapper {
fn from(player_stat: Option<PlayerStatus>) -> Self {
let Some(ps) = player_stat else { return Self::default() };
Self {
duration: ps.duration,
player_state: ps.player_state.map(Into::into),
repeat_mode: ps.repeat_mode.map(Into::into),
shuffle_on: ps.shuffle_on,
content_type: ps.content_type.map(Into::into),
error: ps.error.map(Into::into),
is_live: ps.is_live,
}
}
}