Fixed issue with maintaining audio player "pause" state between application restarts.

This commit is contained in:
2026-08-09 11:51:44 -04:00
parent 2be865d445
commit 895cfdc5f7
2 changed files with 18 additions and 26 deletions

View File

@@ -1,7 +1,6 @@
using Harmonia.Core.Engine;
using Harmonia.Core.Player;
using Harmonia.Core.Playlists;
using System;
using System.Linq;
using System.Threading.Tasks;
@@ -55,17 +54,7 @@ public class SessionRestorer(
if (audioPlayerState.Position > 0 && audioPlayerState.Position <= playlistSong.Song.Length.TotalSeconds)
audioPlayer.Position = audioPlayerState.Position;
switch (audioPlayerState.PlaybackState)
{
case AudioPlaybackState.Playing:
audioPlayer.Play();
break;
case AudioPlaybackState.Paused:
audioPlayer.Pause();
break;
case AudioPlaybackState.Stopped:
audioPlayer.Stop();
break;
}
if (audioPlayerState.PlaybackState == AudioPlaybackState.Playing)
audioPlayer.Play();
}
}

View File

@@ -1,3 +1,4 @@
using Harmonia.Core.Engine;
using Harmonia.Core.Player;
using Harmonia.Core.Playlists;
using System;
@@ -13,7 +14,6 @@ public class SessionTracker(
{
playlistManager.CurrentPlaylistChanged += OnCurrentPlaylistChanged;
audioPlayer.PlayingSongChanged += OnPlayingSongChanged;
audioPlayer.PropertyChanged += OnAudioPlayerPropertyChanged;
}
private void OnCurrentPlaylistChanged(object? sender, EventArgs e)
@@ -28,18 +28,21 @@ public class SessionTracker(
audioPlayerState.PlaylistSongUID = e.NewSong?.UID;
}
private void OnAudioPlayerPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(IAudioPlayer.State):
sessionService.Session.Player.PlaybackState = audioPlayer.State;
break;
}
}
public void Capture()
{
sessionService.Session.Player.Position = audioPlayer.Position;
AudioPlayerState audioPlayerState = sessionService.Session.Player;
audioPlayerState.Position = audioPlayer.Position;
audioPlayerState.PlaybackState = GetSemanticPlaybackState();
}
}
private AudioPlaybackState GetSemanticPlaybackState()
{
if (audioPlayer.PlayingSong is null)
return AudioPlaybackState.Stopped;
return audioPlayer.State == AudioPlaybackState.Playing
? AudioPlaybackState.Playing
: AudioPlaybackState.Paused;
}
}