diff --git a/src/Project/Sucrose.Backgroundog/Extension/Data.cs b/src/Project/Sucrose.Backgroundog/Extension/Data.cs index 6c3aab7a6..ccc326905 100644 --- a/src/Project/Sucrose.Backgroundog/Extension/Data.cs +++ b/src/Project/Sucrose.Backgroundog/Extension/Data.cs @@ -53,11 +53,14 @@ public static JObject GetAudioInfo() return new JObject { { "PID", SBMI.AudioData.PID }, + { "State", SBMI.AudioData.State }, { "Title", SBMI.AudioData.Title }, { "Artist", SBMI.AudioData.Artist }, { "Hwnd", $"{SBMI.AudioData.Hwnd}" }, { "Subtitle", SBMI.AudioData.Subtitle }, { "AlbumTitle", SBMI.AudioData.AlbumTitle }, + { "TrackNumber", SBMI.AudioData.TrackNumber }, + { "AlbumArtist", SBMI.AudioData.AlbumArtist }, { "SourceAppId", SBMI.AudioData.SourceAppId }, { "MediaType", $"{SBMI.AudioData.MediaType}" }, { "PlaybackRate", SBMI.AudioData.PlaybackRate }, @@ -69,11 +72,14 @@ public static JObject GetAudioInfo() { "PlaybackCaps", $"{SBMI.AudioData.PlaybackCaps}" }, { "PlaybackMode", $"{SBMI.AudioData.PlaybackMode}" }, { "ThumbnailString", SBMI.AudioData.ThumbnailString }, + { "AlbumTrackCount", SBMI.AudioData.AlbumTrackCount }, { "PlaybackState", $"{SBMI.AudioData.PlaybackState}" }, { "ThumbnailAddress", SBMI.AudioData.ThumbnailAddress }, { "EndTime", SBMI.AudioData.EndTime.TotalMilliseconds }, { "Position", SBMI.AudioData.Position.TotalMilliseconds }, { "StartTime", SBMI.AudioData.StartTime.TotalMilliseconds }, + { "LastPlayingFileTime", SBMI.AudioData.LastPlayingFileTime }, + { "PositionSetFileTime", SBMI.AudioData.PositionSetFileTime }, { "MinSeekTime", SBMI.AudioData.MinSeekTime.TotalMilliseconds }, { "MaxSeekTime", SBMI.AudioData.MaxSeekTime.TotalMilliseconds } }; diff --git a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs index 52765b803..1fe87e47a 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs @@ -84,8 +84,6 @@ public static async Task Start() SBMI.SessionManager.SessionListChanged += SessionListChanged; } - - SessionListChanged(null, null); }); _ = Task.Run(() => @@ -297,48 +295,62 @@ private static void PrintCurrentSession() { lock (SBMI.LockObject) { - MediaObjectInfo mediaDetails = SBMI.DataSource.GetMediaObjectInfo(); - MediaPlaybackInfo mediaPlaybackInfo = SBMI.DataSource.GetMediaPlaybackInfo(); - MediaTimelineProperties mediaTimeline = SBMI.DataSource.GetMediaTimelineProperties(); - - using Stream thumbnail = SBMI.DataSource.GetThumbnailStream(); - string thumbnailString = thumbnail is null ? null : CreateThumbnail(thumbnail); - - SBMI.AudioData.Title = mediaDetails.Title; - SBMI.AudioData.Artist = mediaDetails.Artist; - SBMI.AudioData.Subtitle = mediaDetails.Subtitle; - SBMI.AudioData.AlbumTitle = mediaDetails.AlbumTitle; - SBMI.AudioData.MediaType = MediaPlaybackDataSource.MediaSchemaToMediaPlaybackMode(mediaDetails.MediaClassPrimaryID); + MediaObjectInfo MediaDetails = SBMI.DataSource.GetMediaObjectInfo(); + MediaPlaybackInfo MediaPlaybackInfo = SBMI.DataSource.GetMediaPlaybackInfo(); + MediaTimelineProperties MediaTimeline = SBMI.DataSource.GetMediaTimelineProperties(); + + using Stream Thumbnail = SBMI.DataSource.GetThumbnailStream(); + string ThumbnailString = Thumbnail is null ? null : CreateThumbnail(Thumbnail); + + SBMI.AudioData.State = true; + SBMI.AudioData.Title = MediaDetails.Title; + SBMI.AudioData.Artist = MediaDetails.Artist; + SBMI.AudioData.Subtitle = MediaDetails.Subtitle; + SBMI.AudioData.AlbumTitle = MediaDetails.AlbumTitle; + SBMI.AudioData.AlbumArtist = MediaDetails.AlbumArtist; + SBMI.AudioData.TrackNumber = MediaDetails.TrackNumber; + SBMI.AudioData.AlbumTrackCount = MediaDetails.AlbumTrackCount; + SBMI.AudioData.MediaType = MediaPlaybackDataSource.MediaSchemaToMediaPlaybackMode(MediaDetails.MediaClassPrimaryID); + + SBMI.AudioData.PID = SBMI.PlayingSession?.PID; + SBMI.AudioData.Hwnd = SBMI.PlayingSession?.Hwnd; SBMI.AudioData.SourceAppId = SBMI.PlayingSession?.SourceAppId; SBMI.AudioData.SourceDeviceId = SBMI.PlayingSession?.SourceDeviceId; SBMI.AudioData.RenderDeviceId = SBMI.PlayingSession?.RenderDeviceId; - SBMI.AudioData.Hwnd = SBMI.PlayingSession?.Hwnd; - SBMI.AudioData.PID = SBMI.PlayingSession?.PID; - SBMI.AudioData.PlaybackState = mediaPlaybackInfo.PlaybackState; - SBMI.AudioData.PlaybackRate = mediaPlaybackInfo.PlaybackRate; - SBMI.AudioData.PlaybackMode = mediaPlaybackInfo.PlaybackMode; - SBMI.AudioData.ShuffleEnabled = mediaPlaybackInfo.ShuffleEnabled; - SBMI.AudioData.RepeatMode = mediaPlaybackInfo.RepeatMode; - SBMI.AudioData.PlaybackCaps = mediaPlaybackInfo.PlaybackCaps; - SBMI.AudioData.PropsValid = mediaPlaybackInfo.PropsValid; - - SBMI.AudioData.StartTime = mediaTimeline.StartTime; - SBMI.AudioData.EndTime = mediaTimeline.EndTime; - SBMI.AudioData.MinSeekTime = mediaTimeline.MinSeekTime; - SBMI.AudioData.MaxSeekTime = mediaTimeline.MaxSeekTime; - SBMI.AudioData.Position = mediaTimeline.Position; - - SBMI.AudioData.ThumbnailString = thumbnailString; - SBMI.AudioData.ThumbnailAddress = "data:image/png;base64," + thumbnailString; + SBMI.AudioData.RepeatMode = MediaPlaybackInfo.RepeatMode; + SBMI.AudioData.PropsValid = MediaPlaybackInfo.PropsValid; + SBMI.AudioData.PlaybackRate = MediaPlaybackInfo.PlaybackRate; + SBMI.AudioData.PlaybackMode = MediaPlaybackInfo.PlaybackMode; + SBMI.AudioData.PlaybackCaps = MediaPlaybackInfo.PlaybackCaps; + SBMI.AudioData.PlaybackState = MediaPlaybackInfo.PlaybackState; + SBMI.AudioData.ShuffleEnabled = MediaPlaybackInfo.ShuffleEnabled; + SBMI.AudioData.LastPlayingFileTime = MediaPlaybackInfo.LastPlayingFileTime; + + SBMI.AudioData.EndTime = MediaTimeline.EndTime; + SBMI.AudioData.Position = MediaTimeline.Position; + SBMI.AudioData.StartTime = MediaTimeline.StartTime; + SBMI.AudioData.MinSeekTime = MediaTimeline.MinSeekTime; + SBMI.AudioData.MaxSeekTime = MediaTimeline.MaxSeekTime; + SBMI.AudioData.PositionSetFileTime = MediaTimeline.PositionSetFileTime; + + SBMI.AudioData.ThumbnailString = ThumbnailString; + + if (string.IsNullOrEmpty(ThumbnailString)) + { + SBMI.AudioData.ThumbnailAddress = ThumbnailString; + } + else + { + SBMI.AudioData.ThumbnailAddress = "data:image/png;base64," + ThumbnailString; + } } } else { lock (SBMI.LockObject) { - Console.Clear(); - Console.WriteLine("There are no active sessions."); + SBMI.AudioData.State = false; } } } diff --git a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs index 3458d5b41..6c0032fb2 100644 --- a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs +++ b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs @@ -81,8 +81,11 @@ internal static class Internal public static SBSDAS AudioData = new() { PID = 0, + State = false, + TrackNumber = 0, PlaybackRate = 0d, Hwnd = IntPtr.Zero, + AlbumTrackCount = 0, Title = string.Empty, Artist = string.Empty, ShuffleEnabled = false, @@ -91,9 +94,12 @@ internal static class Internal Position = TimeSpan.Zero, AlbumTitle = string.Empty, StartTime = TimeSpan.Zero, + AlbumArtist = string.Empty, SourceAppId = string.Empty, MinSeekTime = TimeSpan.Zero, MaxSeekTime = TimeSpan.Zero, + LastPlayingFileTime = new(), + PositionSetFileTime = new(), SourceDeviceId = string.Empty, RenderDeviceId = string.Empty, ThumbnailString = string.Empty, diff --git a/src/Project/Sucrose.Backgroundog/Struct/Data.cs b/src/Project/Sucrose.Backgroundog/Struct/Data.cs index 5806f7479..b9456d99e 100644 --- a/src/Project/Sucrose.Backgroundog/Struct/Data.cs +++ b/src/Project/Sucrose.Backgroundog/Struct/Data.cs @@ -129,6 +129,10 @@ public struct AudioStruct /// /// /// + public bool State; + /// + /// + /// public IntPtr? Hwnd; /// /// @@ -149,6 +153,10 @@ public struct AudioStruct /// /// /// + public uint TrackNumber; + /// + /// + /// public string AlbumTitle; /// /// @@ -157,6 +165,10 @@ public struct AudioStruct /// /// /// + public string AlbumArtist; + /// + /// + /// public string SourceAppId; /// /// @@ -173,6 +185,10 @@ public struct AudioStruct /// /// /// + public uint AlbumTrackCount; + /// + /// + /// public TimeSpan MinSeekTime; /// /// @@ -201,6 +217,14 @@ public struct AudioStruct /// /// /// + public DateTime LastPlayingFileTime; + /// + /// + /// + public DateTime PositionSetFileTime; + /// + /// + /// public MediaPlaybackProps PropsValid; /// ///