()
| 6 | pub use session::get_spotify_session; |
| 7 | |
| 8 | fn main() -> Result<()> { |
| 9 | block_on(async { |
| 10 | let session = get_spotify_session()?; |
| 11 | if session.is_none() { |
| 12 | println!("Spotify is not currently running."); |
| 13 | return Ok(()); |
| 14 | } |
| 15 | |
| 16 | let session = session.unwrap(); |
| 17 | |
| 18 | // Print the current playback status |
| 19 | let playback_info = session.GetPlaybackInfo()?; |
| 20 | let playback_status = playback_info.PlaybackStatus()?; |
| 21 | println!( |
| 22 | "Spotify Playback Status: {:?}", |
| 23 | playback_status == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing |
| 24 | ); |
| 25 | |
| 26 | // Print the current track name |
| 27 | if let Some(media_properties) = session.TryGetMediaPropertiesAsync()?.get().ok() { |
| 28 | println!("Current Track Name: {}", media_properties.Title()?); |
| 29 | println!("Current Artist Name: {}", media_properties.Artist()?); |
| 30 | } else { |
| 31 | println!("Could not retrieve media properties."); |
| 32 | } |
| 33 | |
| 34 | // Get position and track length |
| 35 | let timeline = session.GetTimelineProperties()?; |
| 36 | println!( |
| 37 | "Current Position: {:?}", |
| 38 | timeline.Position()?.Duration / 10_000 |
| 39 | ); |
| 40 | println!( |
| 41 | "Track Duration: {:?}", |
| 42 | timeline.EndTime()?.Duration / 10_000 |
| 43 | ); |
| 44 | |
| 45 | if let Some(media_properties) = session.TryGetMediaPropertiesAsync()?.get().ok() { |
| 46 | println!("Current Track Name: {}", media_properties.Title()?); |
| 47 | println!("Current Artist Name: {}", media_properties.Artist()?); |
| 48 | |
| 49 | // Get cover art thumbnail |
| 50 | let thumbnail = media_properties.Thumbnail()?; // No Option here |
| 51 | let stream_ref = thumbnail.OpenReadAsync()?.get()?; |
| 52 | let size = stream_ref.Size()?; |
| 53 | |
| 54 | let reader = DataReader::CreateDataReader(&stream_ref)?; |
| 55 | reader.LoadAsync(size as u32)?.get()?; |
| 56 | let mut buffer = vec![0u8; size as usize]; |
| 57 | reader.ReadBytes(&mut buffer)?; |
| 58 | |
| 59 | println!("Cover art thumbnail size: {} bytes", buffer.len()); |
| 60 | } |
| 61 | |
| 62 | Ok(()) |
| 63 | }) |
| 64 | } |
nothing calls this directly
no test coverage detected