Updated tests for audio player.

This commit is contained in:
2025-02-24 02:45:47 -05:00
parent 3c2c39e659
commit 960c6b9ec7
2 changed files with 92 additions and 54 deletions

View File

@@ -1,8 +1,6 @@
using Harmonia.Core.Engine;
using Harmonia.Core.Playlists;
using System;
using System.ComponentModel;
using System.Reflection;
namespace Harmonia.Core.Player;
@@ -18,13 +16,15 @@ public class AudioPlayer : IAudioPlayer
{
return _playlist;
}
private set
protected set
{
_playlist = value;
NotifyPropertyChanged(nameof(Playlist));
}
}
protected PlaylistSong? CurrentPlaylistSong { get; set; }
private PlaylistSong? _playingSong;
public PlaylistSong? PlayingSong
{
@@ -32,7 +32,7 @@ public class AudioPlayer : IAudioPlayer
{
return _playingSong;
}
private set
protected set
{
_playingSong = value;
NotifyPropertyChanged(nameof(PlayingSong));
@@ -126,16 +126,13 @@ public class AudioPlayer : IAudioPlayer
{
if (RepeatState == RepeatState.RepeatOne)
{
// Alternative: Set the position to 0 and play again
if (PlayingSong != null)
{
await LoadAsync(PlayingSong, PlaybackMode.LoadAndPlay);
}
return;
Position = 0;
Play();
}
else
{
await NextAsync();
}
await NextAsync();
}
private void OnMusicEngineStateChanged(object? sender, PlaybackStateChangedEventArgs e)
@@ -160,7 +157,7 @@ public class AudioPlayer : IAudioPlayer
public async Task NextAsync()
{
if (Playlist == null || PlayingSong == null || Playlist.Songs.Count == 0)
if (Playlist == null || CurrentPlaylistSong == null || Playlist.Songs.Count == 0)
return;
if (IsRandom)
@@ -170,7 +167,7 @@ public class AudioPlayer : IAudioPlayer
return;
}
int currentIndex = Playlist.Songs.IndexOf(PlayingSong);
int currentIndex = Playlist.Songs.IndexOf(CurrentPlaylistSong);
int nextIndex = currentIndex + 1;
if (nextIndex > Playlist.Songs.Count - 1)
@@ -188,7 +185,7 @@ public class AudioPlayer : IAudioPlayer
public async Task PreviousAsync()
{
if (Playlist == null || PlayingSong == null)
if (Playlist == null || CurrentPlaylistSong == null || Playlist.Songs.Count == 0)
return;
if (Position > PreviousSongSecondsThreshold)
@@ -197,12 +194,12 @@ public class AudioPlayer : IAudioPlayer
return;
}
int currentIndex = Playlist.Songs.IndexOf(PlayingSong);
int currentIndex = Playlist.Songs.IndexOf(CurrentPlaylistSong);
int nextIndex = currentIndex - 1;
if (nextIndex < 0)
{
if (RepeatState == RepeatState.RepeatAll && Playlist.Songs.Count > 0)
if (RepeatState == RepeatState.RepeatAll)
{
await LoadAsync(Playlist.Songs.Count - 1);
return;
@@ -241,6 +238,8 @@ public class AudioPlayer : IAudioPlayer
Playlist = newPlaylist;
}
CurrentPlaylistSong = song;
bool isLoaded = await TryLoadAsync(song);
if (isLoaded == false)