Skip to content

Commit

Permalink
Merge pull request #13 from morzack/master
Browse files Browse the repository at this point in the history
Added Discord Rich Presence support
  • Loading branch information
timweiss authored Jan 19, 2019
2 parents a099f68 + bcb3751 commit 7fd3ef7
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 17 deletions.
Binary file added DiscordRPC/DiscordRPC.dll
Binary file not shown.
7 changes: 6 additions & 1 deletion LunaticPlayer.sln
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.4
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LunaticPlayer", "LunaticPlayer\LunaticPlayer.csproj", "{54C1D563-C319-478E-805B-DA04CB7D90A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LunaticPlayer.GRadioAPI", "LunaticPlayer.GRadioAPI\LunaticPlayer.GRadioAPI.csproj", "{432B7143-97FC-4E49-9D42-4E8C4D3085BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LunaticPlayer.Database", "LunaticPlayer.Database\LunaticPlayer.Database.csproj", "{7E1C563E-7DCF-4420-80EE-6ED3AFC85577}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CAC0043B-9A16-4120-8C1D-A76A9E096AAF}"
ProjectSection(SolutionItems) = preProject
DiscordRPC\DiscordRPC.dll = DiscordRPC\DiscordRPC.dll
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
14 changes: 13 additions & 1 deletion LunaticPlayer/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.109.0" newVersion="1.0.109.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
17 changes: 10 additions & 7 deletions LunaticPlayer/LunaticPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@
<ApplicationIcon>Resources\logo-new-05x.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DiscordRPC">
<HintPath>..\DiscordRPC\DiscordRPC.dll</HintPath>
</Reference>
<Reference Include="GlobalHotKey, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\GlobalHotKey.1.1.0\lib\GlobalHotKey.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.105.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.105.0\lib\net451\System.Data.SQLite.dll</HintPath>
<Reference Include="System.Data.SQLite, Version=1.0.109.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.109.2\lib\net451\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -241,11 +244,11 @@
<Resource Include="Resources\logo-new-05x.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.105.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.105.0\build\net451\System.Data.SQLite.Core.targets')" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.109.2\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.109.2\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.105.0\build\net451\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.105.0\build\net451\System.Data.SQLite.Core.targets'))" />
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.109.2\build\net451\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.109.2\build\net451\System.Data.SQLite.Core.targets'))" />
</Target>
</Project>
56 changes: 50 additions & 6 deletions LunaticPlayer/PlayerInterface.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using LunaticPlayer.Client;
using LunaticPlayer.Controls;
using LunaticPlayer.GRadioAPI.Clients;
using DiscordRPC;

namespace LunaticPlayer
{
Expand Down Expand Up @@ -39,6 +40,9 @@ public partial class MainWindow : Window

private MediaKeyHook _mediaKeyHook;

// discord RPC client
private DiscordRpcClient _discordRpcClient;

public MainWindow()
{
InitializeComponent();
Expand All @@ -51,14 +55,16 @@ public MainWindow()
_interfaceTimer.Interval = 1000;
_interfaceTimer.Elapsed += ReloadInterface;

_radioPlayer.SetVolume(Configuration.GetInstance().Data.Volume);
_radioPlayer.SetVolume(Client.Configuration.GetInstance().Data.Volume);

LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

_fallbackAlbumIcon = new ImageSourceConverter()
.ConvertFromString("pack://application:,,,/LunaticPlayer;component/Resources/gr-album-fallback.png")
as ImageSource;

InitializeDiscord();
}

/// <summary>
Expand Down Expand Up @@ -94,11 +100,13 @@ private async void UpdateSong()
{
animationRun = false;
RunFadeInAnimation();
UpdateDiscordPresence();
}
else if (previousSong.ApiSongId != _currentSong.ApiSongId) // prevents continuous fade in of same song
{
animationRun = false;
RunFadeInAnimation();
UpdateDiscordPresence();
}
}

Expand Down Expand Up @@ -145,7 +153,7 @@ public void PlayButtonClicked()
else
{
_radioPlayer.PlayFromUrl(ApiClient.StreamUrl);
_radioPlayer.SetVolume(Configuration.GetInstance().Data.Volume);
_radioPlayer.SetVolume(Client.Configuration.GetInstance().Data.Volume);
_isPlaying = true;
TBPlayButton.Description = "Stop";

Expand All @@ -165,7 +173,7 @@ public void PlayButtonClicked()
/// </summary>
private void MuteRadioStream()
{
_radioPlayer.ToggleMute(Configuration.GetInstance().Data.Volume);
_radioPlayer.ToggleMute(Client.Configuration.GetInstance().Data.Volume);

if (_radioPlayer.Muted)
{
Expand Down Expand Up @@ -251,7 +259,7 @@ private void VolumeButton_OnClick(object sender, RoutedEventArgs e)
{
if (volumeBar == null)
{
var vol = Configuration.GetInstance().Data.Volume;
var vol = Client.Configuration.GetInstance().Data.Volume;
volumeBar = new VolumeBar(new VolumeBarData() { Volume = vol });
volumeBar.Height = 21;
volumeBar.Width = 100;
Expand Down Expand Up @@ -286,9 +294,10 @@ private void VolumeButton_OnClick(object sender, RoutedEventArgs e)
/// <param name="e"></param>
private void Window_Closed(object sender, EventArgs e)
{
Configuration.GetInstance().Save();
Client.Configuration.GetInstance().Save();
_radioPlayer.Stop();
Application.Current.Shutdown();
DestroyDiscord();
}

private PopupBanner _messageBanner;
Expand Down Expand Up @@ -380,7 +389,42 @@ private void RunFadeInAnimation()
private void OnVolumeChange()
{
_radioPlayer.SetVolume(volumeBar.Data.Volume);
Configuration.GetInstance().Data.Volume = Math.Round(volumeBar.Data.Volume, 2);
Client.Configuration.GetInstance().Data.Volume = Math.Round(volumeBar.Data.Volume, 2);
}

/// <summary>
/// Initializes the Discord RPC API
/// </summary>
private void InitializeDiscord()
{
string clientID = "535310204859056139";
_discordRpcClient = new DiscordRpcClient(clientID);
_discordRpcClient.Initialize();
}

/// <summary>
/// Updates discord presence based on the currently playing song
/// </summary>
private void UpdateDiscordPresence()
{
_discordRpcClient.SetPresence(new RichPresence()
{
Details = "Listening to: " + _currentSong.Title,
State = "By: " + _currentSong.ArtistName,
Timestamps = Timestamps.FromTimeSpan(_currentSong.Duration - _currentSong.PlayedDuration),
Assets = new Assets()
{
LargeImageKey = "large_logo"
}
});
}

/// <summary>
/// Deinitialize the discord RPC API to save resources
/// </summary>
private void DestroyDiscord()
{
_discordRpcClient.Dispose();
}

public bool IsPlaying => _isPlaying;
Expand Down
Binary file added LunaticPlayer/Resources/large_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions LunaticPlayer/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GlobalHotKey" version="1.1.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.1" targetFramework="net452" />
<package id="System.Data.SQLite.Core" version="1.0.105.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net452" />
<package id="System.Data.SQLite.Core" version="1.0.109.2" targetFramework="net452" />
</packages>

0 comments on commit 7fd3ef7

Please sign in to comment.