Add Playback-State Images
This commit is contained in:
parent
140849c0bc
commit
de1a99c501
@ -18,16 +18,24 @@ public class DisMediaRP : IDisposable
|
||||
private readonly ILogger? _logger;
|
||||
private readonly MediaManager _mediaManager = new();
|
||||
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;
|
||||
|
||||
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._currentStatus.Assets.LargeImageKey = largeImageKey ?? "cat";
|
||||
this._discordRpcClient = new DiscordRpcClient(applicationId, logger: new DisLogger(this._logger));
|
||||
this._discordRpcClient.Initialize();
|
||||
this._discordRpcClient.OnError += (sender, args) =>
|
||||
@ -79,12 +87,12 @@ public class DisMediaRP : IDisposable
|
||||
return;
|
||||
|
||||
|
||||
string? playbackState = playbackInfo.PlaybackStatus switch
|
||||
string playbackState = playbackInfo.PlaybackStatus switch
|
||||
{
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Paused => "\u23f8",
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing => "\u25b6",
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Stopped => "\u23f9",
|
||||
_ => null
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Paused => "pause",
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing => "play",
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus.Stopped => "stop",
|
||||
_ => "music"
|
||||
};
|
||||
|
||||
string? repeatMode = playbackInfo.AutoRepeatMode switch
|
||||
@ -96,7 +104,8 @@ public class DisMediaRP : IDisposable
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -3,10 +3,30 @@
|
||||
using DiscordMediaRP;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
int loglevelIndex = Array.IndexOf(args, "-l") + 1;
|
||||
LogLevel? level = loglevelIndex >= 0 && loglevelIndex < args.Length ? Enum.Parse<LogLevel>(args[loglevelIndex]) : null;
|
||||
int discordKeyIndex = Array.IndexOf(args, "-d") + 1;
|
||||
if (discordKeyIndex < 1 || discordKeyIndex >= args.Length)
|
||||
throw new IndexOutOfRangeException("No Discord ApplicationKey provided");
|
||||
string discordKey = args[discordKeyIndex];
|
||||
DisMediaRP _ = new (discordKey, level);
|
||||
int loglevelIndex = Array.IndexOf(args, "-l");
|
||||
LogLevel? level = null;
|
||||
if(loglevelIndex > -1)
|
||||
if(loglevelIndex + 1 < args.Length)
|
||||
level = loglevelIndex < args.Length ? Enum.Parse<LogLevel>(args[loglevelIndex + 1]) : null;
|
||||
else
|
||||
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);
|
1
DiscordMediaRP/media/icons.txt
Normal file
1
DiscordMediaRP/media/icons.txt
Normal file
@ -0,0 +1 @@
|
||||
https://www.flaticon.com/de/autoren/alfanz
|
BIN
DiscordMediaRP/media/music.png
Normal file
BIN
DiscordMediaRP/media/music.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
DiscordMediaRP/media/pause.png
Normal file
BIN
DiscordMediaRP/media/pause.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
DiscordMediaRP/media/play.png
Normal file
BIN
DiscordMediaRP/media/play.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
DiscordMediaRP/media/stop.png
Normal file
BIN
DiscordMediaRP/media/stop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
Loading…
Reference in New Issue
Block a user