sl4f_lib/media_session/
types.rs1use fidl_fuchsia_media_sessions2::{ContentType, Error, PlayerState, PlayerStatus, RepeatMode};
6use serde::Serialize;
7
8#[derive(Debug, Serialize)]
9pub enum SerializablePlayerState {
10 Idle = 0,
11 Playing = 1,
12 Paused = 2,
13 Buffering = 3,
14 Error = 4,
15}
16
17impl From<PlayerState> for SerializablePlayerState {
19 fn from(ps: PlayerState) -> Self {
20 match ps {
21 PlayerState::Idle => Self::Idle,
22 PlayerState::Playing => Self::Playing,
23 PlayerState::Paused => Self::Paused,
24 PlayerState::Buffering => Self::Buffering,
25 PlayerState::Error => Self::Error,
26 }
27 }
28}
29
30#[derive(Debug, Serialize)]
31pub enum SerializableRepeatMode {
32 Off = 0,
33 Group = 1,
34 Single = 2,
35}
36
37impl From<RepeatMode> for SerializableRepeatMode {
39 fn from(m: RepeatMode) -> Self {
40 match m {
41 RepeatMode::Off => Self::Off,
42 RepeatMode::Group => Self::Group,
43 RepeatMode::Single => Self::Single,
44 }
45 }
46}
47
48#[derive(Debug, Serialize)]
49pub enum SerializableContentType {
50 Other = 1,
51 Audio = 2,
52 Video = 3,
53 Music = 4,
54 TvShow = 5,
55 Movie = 6,
56}
57
58impl From<ContentType> for SerializableContentType {
60 fn from(ct: ContentType) -> Self {
61 match ct {
62 ContentType::Other => Self::Other,
63 ContentType::Audio => Self::Audio,
64 ContentType::Video => Self::Video,
65 ContentType::Music => Self::Music,
66 ContentType::TvShow => Self::TvShow,
67 ContentType::Movie => Self::Movie,
68 }
69 }
70}
71
72#[derive(Debug, Serialize)]
73pub enum SerializableError {
74 Other = 1,
75}
76
77impl From<Error> for SerializableError {
79 fn from(e: Error) -> Self {
80 match e {
81 Error::Other => Self::Other,
82 }
83 }
84}
85
86#[derive(Debug, Default, Serialize)]
87pub struct PlayerStatusWrapper {
88 pub duration: Option<i64>,
89 pub player_state: Option<SerializablePlayerState>,
90 pub repeat_mode: Option<SerializableRepeatMode>,
91 pub shuffle_on: Option<bool>,
92 pub content_type: Option<SerializableContentType>,
93 pub error: Option<SerializableError>,
94 pub is_live: Option<bool>,
95}
96
97impl From<Option<PlayerStatus>> for PlayerStatusWrapper {
102 fn from(player_stat: Option<PlayerStatus>) -> Self {
103 let Some(ps) = player_stat else { return Self::default() };
104 Self {
105 duration: ps.duration,
106 player_state: ps.player_state.map(Into::into),
107 repeat_mode: ps.repeat_mode.map(Into::into),
108 shuffle_on: ps.shuffle_on,
109 content_type: ps.content_type.map(Into::into),
110 error: ps.error.map(Into::into),
111 is_live: ps.is_live,
112 }
113 }
114}