gsmtc/model.rs
1use std::fmt::{Debug, Formatter};
2
3/// Represents a playback session from another app providing info about that session.
4///
5/// This model represents a [`GlobalSystemMediaTransportControlsSession`](https://learn.microsoft.com/uwp/api/windows.media.control.globalsystemmediatransportcontrolssession).
6/// It's gradually updated through the [`SessionUpdateEvent`](crate::SessionUpdateEvent).
7#[derive(Debug, Clone)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct SessionModel {
10 /// The current playback info for this session.
11 pub playback: Option<PlaybackModel>,
12 /// The object representing the timeline property values.
13 pub timeline: Option<TimelineModel>,
14 /// The current media item.
15 ///
16 /// This doesn't include the thumbnail. The thumbnail is included in [`SessionUpdateEvent::Media`](crate::SessionUpdateEvent::Media).
17 pub media: Option<MediaModel>,
18 /// The app user model id.
19 ///
20 /// This corresponds to the [`SourceAppUserModelId`](https://learn.microsoft.com/uwp/api/windows.media.control.globalsystemmediatransportcontrolssession.sourceappusermodelid).
21 pub source: String,
22}
23
24/// An image read from a [`IRandomAccessStreamWithContentType`](https://learn.microsoft.com/uwp/api/windows.storage.streams.irandomaccessstreamwithcontenttype).
25#[derive(Eq, PartialEq)]
26pub struct Image {
27 /// The identifier for the format of the data.
28 pub content_type: String,
29 /// The raw bytes of the data.
30 pub data: Vec<u8>,
31}
32
33impl Debug for Image {
34 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
35 f.debug_struct("Image")
36 .field("content_type", &self.content_type)
37 .finish()
38 }
39}
40
41/// The object that holds all of the playback information about a session (Play state, playback type etc.).
42///
43/// Controls are not yet implemented.
44///
45/// This model represents a [`GlobalSystemMediaTransportControlsSessionPlaybackInfo`](https://learn.microsoft.com/uwp/api/windows.media.control.globalsystemmediatransportcontrolssessionplaybackinfo).
46#[derive(Debug, Clone, PartialEq)]
47#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48// TODO: controls
49pub struct PlaybackModel {
50 /// The current playback state of the session.
51 pub status: PlaybackStatus,
52 /// Specifies what type of content the session has.
53 pub r#type: PlaybackType,
54 /// The rate at which playback is happening.
55 pub rate: f64,
56 /// Specifies whether the session is currently playing content in a shuffled order or not.
57 pub shuffle: bool,
58 /// Specifies the repeat mode of the session.
59 pub auto_repeat: AutoRepeatMode,
60}
61
62/// Represents the timeline state of the session (Position, seek ranges etc.).
63///
64/// This model represents a [`GlobalSystemMediaTransportControlsSessionTimelineProperties`](https://learn.microsoft.com/uwp/api/windows.media.control.globalsystemmediatransportcontrolssessiontimelineproperties).
65#[derive(Debug, Clone, Eq, PartialEq)]
66#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67pub struct TimelineModel {
68 /// The starting timestamp of the current media item.
69 pub start: i64,
70 /// The end timestamp of the current media item.
71 pub end: i64,
72 /// The playback position, current as of [`last_updated_at_ms`](TimelineModel::last_updated_at_ms).
73 pub position: i64,
74 /// The UTC time at which the timeline properties were last updated.
75 pub last_updated_at_ms: i64,
76 // TODO: add {Max,Min}SeekTime
77}
78
79/// Holds information about the content that the current session has.
80///
81/// This model represents a [`GlobalSystemMediaTransportControlsSessionMediaProperties`](https://learn.microsoft.com/uwp/api/windows.media.control.globalsystemmediatransportcontrolssessionmediaproperties).
82#[derive(Debug, Clone)]
83#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
84pub struct MediaModel {
85 /// The title.
86 pub title: String,
87 /// The subtitle of the media.
88 pub subtitle: String,
89 /// The Artist name.
90 pub artist: String,
91
92 /// Information about the album this media is contained in.
93 pub album: Option<AlbumModel>,
94 /// The number associated with this track.
95 pub track_number: Option<u32>,
96
97 /// A list of all strings representing the genres.
98 pub genres: Vec<String>,
99 /// The playback type of the content.
100 pub playback_type: PlaybackType,
101}
102
103/// Holds information about an album.
104///
105/// This doesn't represent a WinRT class - it's a convenience wrapper.
106#[derive(Debug, Clone)]
107#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
108pub struct AlbumModel {
109 /// The name of the album artist.
110 pub artist: String,
111 /// The title of the album.
112 pub title: String,
113 /// The total number of tracks on the album.
114 pub track_count: u32,
115}
116
117/// The different states of playback the session could be in.
118///
119/// This represents a [`GlobalSystemMediaTransportControlsSessionPlaybackStatus`](https://learn.microsoft.com/uwp/api/windows.media.control.globalsystemmediatransportcontrolssessionplaybackstatus).
120#[derive(Debug, Clone, Eq, PartialEq)]
121#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
122pub enum PlaybackStatus {
123 /// The media is closed.
124 Closed,
125 /// The media is opened.
126 Opened,
127 /// The media is changing.
128 Changing,
129 /// The media is stopped.
130 Stopped,
131 /// The media is playing.
132 Playing,
133 /// The media is paused.
134 Paused,
135}
136
137/// Defines values for the types of media playback.
138///
139/// This represents a [`MediaPlaybackType`](https://learn.microsoft.com/uwp/api/windows.media.mediaplaybacktype).
140#[derive(Debug, Clone, Eq, PartialEq)]
141#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
142pub enum PlaybackType {
143 /// The media type is unknown.
144 Unknown,
145 /// The media type is audio music.
146 Music,
147 /// The media type is video.
148 Video,
149 /// The media type is an image.
150 Image,
151}
152
153impl Default for PlaybackType {
154 fn default() -> Self {
155 Self::Unknown
156 }
157}
158
159/// Specifies the auto repeat mode for media playback.
160///
161/// This represents a [`MediaPlaybackAutoRepeatMode`](https://learn.microsoft.com/uwp/api/windows.media.mediaplaybackautorepeatmode).
162#[derive(Debug, Clone, Eq, PartialEq)]
163#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
164pub enum AutoRepeatMode {
165 /// No repeating.
166 None,
167 /// Repeat the current track.
168 Track,
169 /// Repeat the current list of tracks.
170 List,
171}
172
173impl Default for AutoRepeatMode {
174 fn default() -> Self {
175 Self::None
176 }
177}