Added tracking/capturing/restoration of audio playback state and position.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Harmonia.Core.Player;
|
||||
using Harmonia.Core.Engine;
|
||||
using Harmonia.Core.Player;
|
||||
using Harmonia.Core.Playlists;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Harmonia.WinUI.Session;
|
||||
|
||||
@@ -10,10 +12,10 @@ public class SessionRestorer(
|
||||
IPlaylistManager playlistManager,
|
||||
IAudioPlayer audioPlayer) : ISessionRestorer
|
||||
{
|
||||
public void Restore()
|
||||
public async Task RestoreAsync()
|
||||
{
|
||||
RestorePlaylist();
|
||||
RestoreAudioPlayer();
|
||||
await RestoreAudioPlayerAsync();
|
||||
}
|
||||
|
||||
private void RestorePlaylist()
|
||||
@@ -31,7 +33,7 @@ public class SessionRestorer(
|
||||
playlistManager.CurrentPlaylist = playlist;
|
||||
}
|
||||
|
||||
private void RestoreAudioPlayer()
|
||||
private async Task RestoreAudioPlayerAsync()
|
||||
{
|
||||
AudioPlayerState audioPlayerState = sessionService.Session.Player;
|
||||
|
||||
@@ -43,13 +45,27 @@ public class SessionRestorer(
|
||||
if (playlist is null)
|
||||
return;
|
||||
|
||||
PlaylistSong? song = playlist.Songs.FirstOrDefault(s => s.UID == audioPlayerState.PlaylistSongUID);
|
||||
PlaylistSong? playlistSong = playlist.Songs.FirstOrDefault(s => s.UID == audioPlayerState.PlaylistSongUID);
|
||||
|
||||
if (song is null)
|
||||
if (playlistSong is null)
|
||||
return;
|
||||
|
||||
//PlaybackMode playbackMode = audioPlayerState.PlaybackState
|
||||
await audioPlayer.LoadAsync(playlistSong, PlaybackMode.LoadOnly);
|
||||
|
||||
audioPlayer.LoadAsync(song, PlaybackMode.LoadOnly);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user