Skip to content

Commit

Permalink
fix: Duration not present on message
Browse files Browse the repository at this point in the history
  • Loading branch information
Marconi Gomes committed Sep 10, 2023
1 parent fa67a74 commit 54d9ad5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
13 changes: 13 additions & 0 deletions AMRPC WatchDog Desktop/Payload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Payload
{
private string _playerStateValue;
private double _endTimeValue = -1;
private double _duration = -1;

public event PropertyChangedEventHandler PropertyChanged;

Expand Down Expand Up @@ -44,6 +45,17 @@ public double endTime
NotifyPropertyChanged();
}
}

public double duration
{
get => _duration;
set
{
if (value == _duration) return;
_duration = value;
NotifyPropertyChanged();
}
}

private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
Expand All @@ -58,6 +70,7 @@ public void ResetToInitialState()
thumbnailPath = null;
playerState = PlayingStatuses.NotStarted;
endTime = -1;
duration = -1;
}
}
}
3 changes: 2 additions & 1 deletion AMRPC WatchDog Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace AMRPC_WatchDog_Desktop
internal static class Program
{

private const string AppVersion = "v0.2.4";
private const string AppVersion = "v0.2.4";

[STAThread]
private static void Main()
{
Expand Down
9 changes: 4 additions & 5 deletions AMRPC WatchDog Desktop/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ private void OnPlaybackInfoChanged(GlobalSystemMediaTransportControlsSession sen

_payload.playerState = playbackInfo.PlaybackStatus.ToString().ToLower() == Payload.PlayingStatuses.Playing
? Payload.PlayingStatuses.Playing : Payload.PlayingStatuses.Paused;

Double newEndTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() +
timelineProperties.EndTime.TotalMilliseconds;
_payload.endTime = newEndTime;

_payload.endTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + timelineProperties.EndTime.TotalMilliseconds;
_payload.duration = timelineProperties.EndTime.TotalSeconds - timelineProperties.StartTime.TotalSeconds;
}

private async void OnMediaPropertiesChanged(GlobalSystemMediaTransportControlsSession sender, MediaPropertiesChangedEventArgs args)
Expand All @@ -88,7 +87,7 @@ private async void OnMediaPropertiesChanged(GlobalSystemMediaTransportControlsSe

private void ParseMediaProperties(GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties)
{
_payload.artist = mediaProperties.AlbumArtist.Split('-').First().Trim();
_payload.artist = mediaProperties.AlbumArtist.Split('').First().Trim();
_payload.album = mediaProperties.AlbumArtist.Split('—').Last().Trim();
// payload.ThumbnailPath = mediaProperties.Thumbnail;
_payload.title = mediaProperties.Title;
Expand Down

0 comments on commit 54d9ad5

Please sign in to comment.