1
0

Add Playback-State Images

This commit is contained in:
glax 2024-02-22 03:24:18 +01:00
parent 140849c0bc
commit de1a99c501
7 changed files with 46 additions and 16 deletions

View File

@ -18,16 +18,24 @@ public class DisMediaRP : IDisposable
private readonly ILogger? _logger; private readonly ILogger? _logger;
private readonly MediaManager _mediaManager = new(); private readonly MediaManager _mediaManager = new();
private readonly DiscordRpcClient _discordRpcClient; private readonly DiscordRpcClient _discordRpcClient;
private readonly RichPresence _currentStatus = new(); private readonly RichPresence _currentStatus = new()
{
Assets = new()
{
LargeImageText = "C9Glax/DiscordMediaRichPresence",
SmallImageText = "https://www.flaticon.com/de/autoren/alfanz"
}
};
private bool _running = true; private bool _running = true;
public DisMediaRP(string applicationId, LogLevel? logLevel) : this(applicationId, new Logger(logLevel ?? LogLevel.Information)) public DisMediaRP(string applicationId, LogLevel? logLevel, string? largeImageKey = null) : this(applicationId, new Logger(logLevel ?? LogLevel.Information), largeImageKey)
{ {
} }
public DisMediaRP(string applicationId, ILogger? logger) public DisMediaRP(string applicationId, ILogger? logger = null, string? largeImageKey = null)
{ {
this._logger = logger; this._logger = logger;
this._currentStatus.Assets.LargeImageKey = largeImageKey ?? "cat";
this._discordRpcClient = new DiscordRpcClient(applicationId, logger: new DisLogger(this._logger)); this._discordRpcClient = new DiscordRpcClient(applicationId, logger: new DisLogger(this._logger));
this._discordRpcClient.Initialize(); this._discordRpcClient.Initialize();
this._discordRpcClient.OnError += (sender, args) => this._discordRpcClient.OnError += (sender, args) =>
@ -79,12 +87,12 @@ public class DisMediaRP : IDisposable
return; return;
string? playbackState = playbackInfo.PlaybackStatus switch string playbackState = playbackInfo.PlaybackStatus switch
{ {
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Paused => "\u23f8", GlobalSystemMediaTransportControlsSessionPlaybackStatus.Paused => "pause",
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing => "\u25b6", GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing => "play",
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Stopped => "\u23f9", GlobalSystemMediaTransportControlsSessionPlaybackStatus.Stopped => "stop",
_ => null _ => "music"
}; };
string? repeatMode = playbackInfo.AutoRepeatMode switch string? repeatMode = playbackInfo.AutoRepeatMode switch
@ -96,7 +104,8 @@ public class DisMediaRP : IDisposable
string? shuffle = (playbackInfo.IsShuffleActive ?? false) ? "\ud83d\udd00" : null; string? shuffle = (playbackInfo.IsShuffleActive ?? false) ? "\ud83d\udd00" : null;
this._currentStatus.State = string.Join(' ', playbackState, repeatMode, shuffle, mediaSession.Id); this._currentStatus.State = string.Join(' ', repeatMode, shuffle);
this._currentStatus.Assets.SmallImageKey = playbackState;
this._discordRpcClient.SetPresence(this._currentStatus); this._discordRpcClient.SetPresence(this._currentStatus);
} }

View File

@ -3,10 +3,30 @@
using DiscordMediaRP; using DiscordMediaRP;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
int loglevelIndex = Array.IndexOf(args, "-l") + 1; int loglevelIndex = Array.IndexOf(args, "-l");
LogLevel? level = loglevelIndex >= 0 && loglevelIndex < args.Length ? Enum.Parse<LogLevel>(args[loglevelIndex]) : null; LogLevel? level = null;
int discordKeyIndex = Array.IndexOf(args, "-d") + 1; if(loglevelIndex > -1)
if (discordKeyIndex < 1 || discordKeyIndex >= args.Length) if(loglevelIndex + 1 < args.Length)
throw new IndexOutOfRangeException("No Discord ApplicationKey provided"); level = loglevelIndex < args.Length ? Enum.Parse<LogLevel>(args[loglevelIndex + 1]) : null;
string discordKey = args[discordKeyIndex]; else
DisMediaRP _ = new (discordKey, level); throw new IndexOutOfRangeException(nameof(loglevelIndex));
int discordKeyIndex = Array.IndexOf(args, "-d");
string discordKey;
if (loglevelIndex > -1)
if(discordKeyIndex + 1 < args.Length)
discordKey = args[discordKeyIndex + 1];
else
throw new IndexOutOfRangeException("No Discord ApplicationKey provided");
else
throw new ArgumentNullException(nameof(discordKey));
int imageKeyIndex = Array.IndexOf(args, "-i");
string? imageKey = null;
if(imageKeyIndex > -1)
if (imageKeyIndex + 1 < args.Length)
imageKey = args[imageKeyIndex + 1];
else
throw new IndexOutOfRangeException(nameof(imageKeyIndex));
DisMediaRP _ = new (discordKey, level, imageKey);

View File

@ -0,0 +1 @@
https://www.flaticon.com/de/autoren/alfanz

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB