11#[ cfg( target_os = "macos" ) ]
22mod macos;
3- #[ cfg( not( any(
4- target_os = "macos"
5- ) ) ) ]
3+ #[ cfg( not( any( target_os = "macos" ) ) ) ]
64mod null;
75
86pub trait MediaBackend {
@@ -22,7 +20,7 @@ pub trait MediaBackend {
2220#[ derive( Clone , Copy , PartialEq ) ]
2321pub enum MediaType {
2422 Audio ,
25- Video
23+ Video ,
2624}
2725
2826pub struct Metadata {
@@ -41,14 +39,11 @@ pub struct MediaSession {
4139}
4240
4341impl MediaSession {
44-
4542 pub fn new ( ) -> Self {
4643 #[ cfg( target_os = "macos" ) ]
4744 let backend = Box :: new ( macos:: NowPlayingBackend :: new ( ) ) ;
4845
49- #[ cfg( not( any(
50- target_os = "macos"
51- ) ) ) ]
46+ #[ cfg( not( any( target_os = "macos" ) ) ) ]
5247 let backend = Box :: new ( null:: NullBackend :: new ( ) ) ;
5348
5449 Self {
@@ -78,71 +73,69 @@ impl MediaSession {
7873 self . metadata . artist = artist. to_string ( ) ;
7974 self . backend . set_artist ( artist) ;
8075 }
81-
76+
8277 pub fn artist ( & self ) -> & str {
8378 & self . metadata . artist
8479 }
85-
80+
8681 pub fn set_album ( & mut self , album : & str ) {
8782 self . metadata . album = album. to_string ( ) ;
8883 self . backend . set_album ( album) ;
8984 }
90-
85+
9186 pub fn album ( & self ) -> & str {
9287 & self . metadata . album
9388 }
94-
89+
9590 pub fn set_genre ( & mut self , genre : & str ) {
9691 self . metadata . genre = genre. to_string ( ) ;
9792 self . backend . set_album ( genre) ;
9893 }
99-
94+
10095 pub fn genre ( & self ) -> & str {
10196 & self . metadata . genre
10297 }
103-
98+
10499 pub fn set_media_type ( & mut self , media_type : MediaType ) {
105100 self . metadata . media_type = media_type;
106101 self . backend . set_media_type ( media_type) ;
107102 }
108-
103+
109104 pub fn media_type ( & self ) -> MediaType {
110105 self . metadata . media_type
111106 }
112-
107+
113108 pub fn set_playback_duration ( & mut self , duration : f64 ) {
114109 self . metadata . duration = duration;
115110 self . backend . set_playback_duration ( duration) ;
116111 }
117-
112+
118113 pub fn duration ( & self ) -> f64 {
119114 self . metadata . duration
120115 }
121-
116+
122117 pub fn set_elapsed_duration ( & self , duration : f64 ) {
123118 self . backend . set_elapsed_duration ( duration) ;
124119 }
125-
120+
126121 pub fn set_playback_rate ( & mut self , rate : f64 ) {
127122 self . metadata . playback_rate = rate;
128123 self . backend . set_playback_rate ( rate) ;
129124 }
130-
125+
131126 pub fn playback_rate ( & self ) -> f64 {
132127 self . metadata . playback_rate
133128 }
134129
135130 pub fn start ( & self ) {
136131 self . backend . start_session ( ) ;
137132 }
138-
133+
139134 pub fn stop ( & self ) {
140135 self . backend . stop_session ( ) ;
141136 }
142-
143137}
144138
145-
146139#[ cfg( test) ]
147140mod tests {
148141 use super :: * ;
0 commit comments