-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,162 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.32413.511 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogiMusicApplet", "LogiMusicApplet\LogiMusicApplet.csproj", "{6A7C0BB2-C6F7-475E-B315-9BA3CE82BA48}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6A7C0BB2-C6F7-475E-B315-9BA3CE82BA48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6A7C0BB2-C6F7-475E-B315-9BA3CE82BA48}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6A7C0BB2-C6F7-475E-B315-9BA3CE82BA48}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6A7C0BB2-C6F7-475E-B315-9BA3CE82BA48}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {47D8D771-784C-4644-A216-BD93F71686D5} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{6A7C0BB2-C6F7-475E-B315-9BA3CE82BA48}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>LogiMusicApplet</RootNamespace> | ||
<AssemblyName>LogiMusicApplet</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<Deterministic>true</Deterministic> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject /> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationIcon>stereo.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="TrayHelper.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="LogiFrame"> | ||
<Version>2.1.2</Version> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Windows.SDK.Contracts"> | ||
<Version>10.0.22000.196</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="stereo.ico" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
using LogiFrame; | ||
using Microsoft.Win32; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Drawing.Drawing2D; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using Windows.Media.Control; | ||
using Windows.Storage; | ||
using Windows.UI.Xaml.Media.Imaging; | ||
|
||
namespace LogiMusicApplet | ||
{ | ||
class Program | ||
{ | ||
private static readonly int bgAfter = 10000; | ||
|
||
|
||
private static GlobalSystemMediaTransportControlsSessionManager sessionManager; | ||
private static GlobalSystemMediaTransportControlsSession currentSession; | ||
private static GlobalSystemMediaTransportControlsSessionMediaProperties mediaProps; | ||
private static GlobalSystemMediaTransportControlsSessionPlaybackStatus playbackStatus; | ||
private static GlobalSystemMediaTransportControlsSessionTimelineProperties timeLineProps; | ||
|
||
private static LCDPicture lcdMediaArt; | ||
private static LCDLabel lcdCurrentlyPlaying; | ||
private static LCDMarquee lcdMediaTitle; | ||
private static LCDLabel lcdStatus; | ||
private static LCDLabel lcdArtist; | ||
private static LCDApp lcdApp; | ||
private static LCDProgressBar lcdBar; | ||
|
||
private static DateTime bgTime; | ||
|
||
private static TrayHelper trayHelper; | ||
|
||
static async Task Main() | ||
{ | ||
trayHelper = new TrayHelper(); | ||
|
||
// Create a control. | ||
lcdMediaTitle = new LCDMarquee | ||
{ | ||
Font = PixelFonts.Small, // The PixelFonts class contains various good fonts for LCD screens. | ||
Size = new Size(LCDApp.DefaultSize.Width, PixelFonts.Small.Height), | ||
Location = new Point(48, 12), | ||
}; | ||
|
||
//lcdMediaTitle.TextAlign = ContentAlignment.MiddleCenter; | ||
lcdMediaTitle.Font = new Font(PixelFonts.Small, FontStyle.Bold); | ||
|
||
lcdArtist = new LCDLabel | ||
{ | ||
Font = PixelFonts.Small, | ||
Size = new Size(LCDApp.DefaultSize.Width - 48, PixelFonts.Small.Height), | ||
Location = new Point(48, 12 + PixelFonts.Small.Height), | ||
}; | ||
|
||
lcdArtist.TextAlign = ContentAlignment.MiddleCenter; | ||
|
||
lcdStatus = new LCDLabel | ||
{ | ||
Font = PixelFonts.Small, | ||
Size = new Size(LCDApp.DefaultSize.Width - 48, PixelFonts.Small.Height), | ||
Location = new Point(48, 29), | ||
Text = "⏹", | ||
}; | ||
|
||
lcdStatus.TextAlign = ContentAlignment.MiddleCenter; | ||
|
||
lcdCurrentlyPlaying = new LCDLabel | ||
{ | ||
Font = PixelFonts.Title, | ||
Text = "Currently Playing", | ||
Size = new Size(LCDApp.DefaultSize.Width - 48, PixelFonts.Title.Height), | ||
Location = new Point(48, 2), | ||
}; | ||
|
||
lcdCurrentlyPlaying.TextAlign = ContentAlignment.MiddleCenter; | ||
|
||
lcdBar = new LCDProgressBar | ||
{ | ||
Location = new Point(12 + 48, 37), | ||
Size = new Size(136 - 48, 6), | ||
Style = LogiFrame.BorderStyle.Border, | ||
Direction = ProgressBarDirection.Right, | ||
Value = 50 | ||
}; | ||
|
||
lcdMediaArt = new LCDPicture | ||
{ | ||
Location = new Point(0, 0), | ||
Size = new Size(48, 48), // Resources.gtech is the image we want to draw on the screen. | ||
}; | ||
|
||
// Create an app instance. | ||
lcdApp = new LCDApp("LogiMusic", false, false, false); | ||
|
||
// Add the label control to the app. | ||
|
||
lcdApp.Controls.Add(lcdMediaTitle); | ||
lcdApp.Controls.Add(lcdArtist); | ||
lcdApp.Controls.Add(lcdCurrentlyPlaying); | ||
lcdApp.Controls.Add(lcdBar); | ||
lcdApp.Controls.Add(lcdStatus); | ||
lcdApp.Controls.Add(lcdMediaArt); | ||
|
||
sessionManager = await GlobalSystemMediaTransportControlsSessionManager.RequestAsync(); | ||
sessionManager.CurrentSessionChanged += OnSessionChanged; | ||
|
||
await UpdateSessionInfo(); | ||
|
||
|
||
// Make the app the foreground app on the LCD screen. | ||
lcdApp.PushToForeground(); | ||
|
||
SendToBackground(); | ||
|
||
// A blocking call. Waits for the LCDApp instance to be disposed. (optional) | ||
lcdApp.WaitForClose(); | ||
} | ||
|
||
private static async void OnSessionChanged(GlobalSystemMediaTransportControlsSessionManager sender, CurrentSessionChangedEventArgs args) | ||
{ | ||
await UpdateSessionInfo(); | ||
} | ||
|
||
private static async Task UpdateSessionInfo() | ||
{ | ||
currentSession = sessionManager.GetCurrentSession(); | ||
|
||
if (currentSession != null) | ||
{ | ||
currentSession.TimelinePropertiesChanged -= OnTimeLineUpdated; | ||
currentSession.MediaPropertiesChanged -= async (s, e) => { await OnMediaChangedAsync(s, e); }; | ||
currentSession.PlaybackInfoChanged -= OnPlaybackUpdated; | ||
|
||
currentSession.TimelinePropertiesChanged += OnTimeLineUpdated; | ||
currentSession.MediaPropertiesChanged += async (s, e) => { await OnMediaChangedAsync(s, e); }; | ||
currentSession.PlaybackInfoChanged += OnPlaybackUpdated; | ||
|
||
await UpdateMediaInfoAsync(); | ||
UpdatePlaybackInfo(); | ||
} | ||
} | ||
|
||
|
||
private static async Task UpdateMediaInfoAsync() | ||
{ | ||
if (currentSession == null) currentSession = sessionManager.GetCurrentSession(); | ||
|
||
mediaProps = await currentSession.TryGetMediaPropertiesAsync(); | ||
|
||
lcdMediaTitle.Text = mediaProps.Title; | ||
lcdArtist.Text = mediaProps.Artist; | ||
if (mediaProps.Thumbnail == null) return; | ||
lcdMediaArt.Image = ResizeImage(Image.FromStream((await mediaProps.Thumbnail.OpenReadAsync()).AsStreamForRead()), new Size(48, 48)); | ||
} | ||
|
||
private static void UpdatePlaybackInfo() | ||
{ | ||
if (!lcdApp.Visible) return; | ||
|
||
if (currentSession == null) currentSession = sessionManager.GetCurrentSession(); | ||
|
||
if (currentSession == null) return; | ||
|
||
GlobalSystemMediaTransportControlsSessionPlaybackInfo playbackInfo = currentSession.GetPlaybackInfo(); | ||
|
||
if (playbackInfo != null) playbackStatus = playbackInfo.PlaybackStatus; | ||
else playbackStatus = GlobalSystemMediaTransportControlsSessionPlaybackStatus.Stopped; | ||
|
||
if (currentSession == null) return; | ||
timeLineProps = currentSession.GetTimelineProperties(); | ||
|
||
|
||
switch (playbackStatus) | ||
{ | ||
case GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing: | ||
lcdStatus.Text = "▶"; | ||
break; | ||
case GlobalSystemMediaTransportControlsSessionPlaybackStatus.Paused: | ||
lcdStatus.Text = "⏸"; | ||
break; | ||
default: | ||
lcdStatus.Text = "⏹"; | ||
break; | ||
} | ||
|
||
lcdStatus.Text += timeLineProps.Position.ToString(); | ||
|
||
lcdBar.Value = (int)(timeLineProps.Position.TotalSeconds / (timeLineProps.EndTime.TotalSeconds - timeLineProps.StartTime.TotalSeconds)) * 100; | ||
} | ||
|
||
public static void OnTimeLineUpdated(GlobalSystemMediaTransportControlsSession session, TimelinePropertiesChangedEventArgs arg) | ||
{ | ||
UpdatePlaybackInfo(); | ||
} | ||
|
||
private static void OnPlaybackUpdated(GlobalSystemMediaTransportControlsSession sender, PlaybackInfoChangedEventArgs args) | ||
{ | ||
lcdApp.PushToForeground(); | ||
|
||
UpdatePlaybackInfo(); | ||
|
||
SendToBackground(); | ||
} | ||
|
||
public static async Task OnMediaChangedAsync(GlobalSystemMediaTransportControlsSession session, MediaPropertiesChangedEventArgs _args) | ||
{ | ||
lcdApp.PushToForeground(); | ||
|
||
await UpdateSessionInfo(); | ||
|
||
SendToBackground(); | ||
} | ||
|
||
private static void SendToBackground() | ||
{ | ||
System.Threading.Tasks.Task.Factory.StartNew(() => | ||
{ | ||
bgTime = DateTime.Now.AddSeconds(bgAfter / 1000); | ||
while(bgTime > DateTime.Now) | ||
{ | ||
Thread.Sleep(bgAfter / 4); | ||
} | ||
lcdApp.PushToBackground(); | ||
}); | ||
} | ||
|
||
private static System.Drawing.Image ResizeImage(System.Drawing.Image imgToResize, Size size) | ||
{ | ||
//Get the image current width | ||
int sourceWidth = imgToResize.Width; | ||
//Get the image current height | ||
int sourceHeight = imgToResize.Height; | ||
|
||
float nPercent; | ||
float nPercentW; | ||
float nPercentH; | ||
|
||
//Calulate width with new desired size | ||
nPercentW = ((float)size.Width / (float)sourceWidth); | ||
//Calculate height with new desired size | ||
nPercentH = ((float)size.Height / (float)sourceHeight); | ||
if (nPercentH < nPercentW) | ||
nPercent = nPercentW; | ||
else | ||
nPercent = nPercentH; | ||
//New Width | ||
int destWidth = (int)(sourceWidth * nPercent); | ||
//New Height | ||
int destHeight = (int)(sourceHeight * nPercent); | ||
Bitmap b = new Bitmap(destWidth, destHeight); | ||
Graphics g = Graphics.FromImage((System.Drawing.Image)b); | ||
g.InterpolationMode = InterpolationMode.High; | ||
// Draw image with new width and height | ||
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight); | ||
g.Dispose(); | ||
return (System.Drawing.Image)b; | ||
} | ||
} | ||
} |
Oops, something went wrong.