Skip to content

Commit

Permalink
Preparing Backgroundog
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 19, 2023
1 parent 0258d93 commit 3abd6f1
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 34 deletions.
6 changes: 6 additions & 0 deletions src/Project/Sucrose.Backgroundog/Extension/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 }
};
Expand Down
80 changes: 46 additions & 34 deletions src/Project/Sucrose.Backgroundog/Helper/Specification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public static async Task Start()

SBMI.SessionManager.SessionListChanged += SessionListChanged;
}

SessionListChanged(null, null);
});

_ = Task.Run(() =>
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Project/Sucrose.Backgroundog/Manage/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions src/Project/Sucrose.Backgroundog/Struct/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public struct AudioStruct
/// <summary>
///
/// </summary>
public bool State;
/// <summary>
///
/// </summary>
public IntPtr? Hwnd;
/// <summary>
///
Expand All @@ -149,6 +153,10 @@ public struct AudioStruct
/// <summary>
///
/// </summary>
public uint TrackNumber;
/// <summary>
///
/// </summary>
public string AlbumTitle;
/// <summary>
///
Expand All @@ -157,6 +165,10 @@ public struct AudioStruct
/// <summary>
///
/// </summary>
public string AlbumArtist;
/// <summary>
///
/// </summary>
public string SourceAppId;
/// <summary>
///
Expand All @@ -173,6 +185,10 @@ public struct AudioStruct
/// <summary>
///
/// </summary>
public uint AlbumTrackCount;
/// <summary>
///
/// </summary>
public TimeSpan MinSeekTime;
/// <summary>
///
Expand Down Expand Up @@ -201,6 +217,14 @@ public struct AudioStruct
/// <summary>
///
/// </summary>
public DateTime LastPlayingFileTime;
/// <summary>
///
/// </summary>
public DateTime PositionSetFileTime;
/// <summary>
///
/// </summary>
public MediaPlaybackProps PropsValid;
/// <summary>
///
Expand Down

0 comments on commit 3abd6f1

Please sign in to comment.