Fixed loading multiple songs issue.
This commit is contained in:
@@ -9,6 +9,8 @@ public class AudioPlayer : IAudioPlayer
|
||||
private readonly IAudioEngine _audioEngine;
|
||||
private readonly IPlaylistManager _playlistManager;
|
||||
|
||||
private int _loadVersion;
|
||||
|
||||
private Playlist? _playlist;
|
||||
public Playlist? Playlist
|
||||
{
|
||||
@@ -241,8 +243,15 @@ public class AudioPlayer : IAudioPlayer
|
||||
|
||||
CurrentPlaylistSong = song;
|
||||
|
||||
int loadVersion = Interlocked.Increment(ref _loadVersion);
|
||||
|
||||
bool isLoaded = await TryLoadAsync(song);
|
||||
|
||||
// A newer load request was started while this one was in flight;
|
||||
// abandon this one so only the latest request controls playback.
|
||||
if (loadVersion != Volatile.Read(ref _loadVersion))
|
||||
return false;
|
||||
|
||||
if (isLoaded == false)
|
||||
{
|
||||
if (mode == PlaybackMode.LoadAndPlay)
|
||||
|
||||
Reference in New Issue
Block a user