mirror of
https://github.com/4sval/FModel.git
synced 2026-05-07 13:31:58 -05:00
Clear _waveSource and PlayedFile if last file was removed
This commit is contained in:
parent
879063cf53
commit
f21060105d
|
|
@ -238,6 +238,20 @@ public class AudioPlayerViewModel : ViewModel, ISource, IDisposable
|
|||
});
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
_waveSource = null;
|
||||
|
||||
PlayedFile = new AudioFile(-1, "No audio file");
|
||||
Spectrum = null;
|
||||
|
||||
RaiseSourceEvent(ESourceEventType.Clearing);
|
||||
ClearSoundOut();
|
||||
});
|
||||
}
|
||||
|
||||
public void AddToPlaylist(byte[] data, string filePath)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
|
|
@ -274,6 +288,18 @@ public class AudioPlayerViewModel : ViewModel, ISource, IDisposable
|
|||
{
|
||||
_audioFiles[i].Id = i;
|
||||
}
|
||||
|
||||
if (_audioFiles.Count < 1)
|
||||
{
|
||||
Unload();
|
||||
return;
|
||||
}
|
||||
|
||||
SelectedAudioFile = _audioFiles[SelectedAudioFile.Id];
|
||||
|
||||
if (!removedPlaying) return;
|
||||
Load();
|
||||
Play();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -525,6 +551,11 @@ public class AudioPlayerViewModel : ViewModel, ISource, IDisposable
|
|||
_soundOut.Volume = UserSettings.Default.AudioPlayerVolume / 100;
|
||||
}
|
||||
|
||||
private void ClearSoundOut()
|
||||
{
|
||||
_soundOut = null;
|
||||
}
|
||||
|
||||
private IEnumerable<MMDevice> EnumerateDevices()
|
||||
{
|
||||
using var deviceEnumerator = new MMDeviceEnumerator();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ namespace FModel.Views.Resources.Controls.Aup;
|
|||
|
||||
public enum ESourceEventType
|
||||
{
|
||||
Loading
|
||||
Loading,
|
||||
Clearing
|
||||
}
|
||||
|
||||
public class SourceEventArgs : EventArgs
|
||||
|
|
@ -15,4 +16,4 @@ public class SourceEventArgs : EventArgs
|
|||
{
|
||||
Event = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user