Fixed issue with maintaining audio player "pause" state between application restarts.
This commit is contained in:
@@ -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:
|
||||
if (audioPlayerState.PlaybackState == AudioPlaybackState.Playing)
|
||||
audioPlayer.Play();
|
||||
break;
|
||||
case AudioPlaybackState.Paused:
|
||||
audioPlayer.Pause();
|
||||
break;
|
||||
case AudioPlaybackState.Stopped:
|
||||
audioPlayer.Stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user