diff --git a/source/TextBlade.Core/IO/SerialSoundPlayer.cs b/source/TextBlade.Core/IO/SerialSoundPlayer.cs index e3f2999..8a0d953 100644 --- a/source/TextBlade.Core/IO/SerialSoundPlayer.cs +++ b/source/TextBlade.Core/IO/SerialSoundPlayer.cs @@ -34,6 +34,7 @@ private void PlayNext() return; } + _soundPlayer.Stop(); _soundPlayer.Load(_audiosToPlay[_currentAudioId]); _soundPlayer.Play(); } diff --git a/source/TextBlade.Core/Services/ISoundPlayer.cs b/source/TextBlade.Core/Services/ISoundPlayer.cs index 02beeb2..9d99b75 100644 --- a/source/TextBlade.Core/Services/ISoundPlayer.cs +++ b/source/TextBlade.Core/Services/ISoundPlayer.cs @@ -2,7 +2,8 @@ public interface ISoundPlayer : IDisposable { - public event Action? OnPlaybackComplete; + public Action? OnPlaybackComplete { get; set; } + public bool LoopPlayback { get; set; } void Load(string audioFile); void Play(); void Stop(); diff --git a/source/TextBlade.Core/Services/NullSoundPlayer.cs b/source/TextBlade.Core/Services/NullSoundPlayer.cs index 77963bd..1635ddd 100644 --- a/source/TextBlade.Core/Services/NullSoundPlayer.cs +++ b/source/TextBlade.Core/Services/NullSoundPlayer.cs @@ -3,7 +3,8 @@ namespace TextBlade.Core.Services { public sealed class NullSoundPlayer : ISoundPlayer { - public event Action? OnPlaybackComplete; + public Action? OnPlaybackComplete { get; set; } + public bool LoopPlayback { get; set; } public void Dispose() { diff --git a/source/TextBlade.Platform.Windows/Audio/NAudioSoundPlayer.cs b/source/TextBlade.Platform.Windows/Audio/NAudioSoundPlayer.cs index 2867e77..4ac41c4 100644 --- a/source/TextBlade.Platform.Windows/Audio/NAudioSoundPlayer.cs +++ b/source/TextBlade.Platform.Windows/Audio/NAudioSoundPlayer.cs @@ -6,7 +6,8 @@ namespace TextBlade.Platform.Windows.Audio; public class NAudioSoundPlayer : ISoundPlayer { - public event Action? OnPlaybackComplete; + public Action? OnPlaybackComplete { get; set; } + public bool LoopPlayback { get; set; } private const string SupportedAudioExtension = "ogg"; private const float VolumeMultiplier = 0.5f; @@ -23,7 +24,7 @@ public void Load(string audioFile) _waveOut.PlaybackStopped += (sender, stoppedArgs) => { - if (!ShouldLoopPlayback) + if (!LoopPlayback) { OnPlaybackComplete?.Invoke(); return; @@ -39,8 +40,6 @@ public void Load(string audioFile) public void Play() => _waveOut?.Play(); public void Stop() =>_waveOut?.Stop(); - private bool ShouldLoopPlayback => OnPlaybackComplete == null; - protected virtual void Dispose(bool disposing) { if (!_disposedValue) diff --git a/source/TextBlade.Platform.Windows/Audio/SonicBoomSoundPlayer.cs b/source/TextBlade.Platform.Windows/Audio/SonicBoomSoundPlayer.cs index d457f51..ae26e74 100644 --- a/source/TextBlade.Platform.Windows/Audio/SonicBoomSoundPlayer.cs +++ b/source/TextBlade.Platform.Windows/Audio/SonicBoomSoundPlayer.cs @@ -5,12 +5,38 @@ namespace TextBlade.Platform.Windows.Audio; public class SonicBoomSoundPlayer : ISoundPlayer { - public event Action? OnPlaybackComplete; + public Action? OnPlaybackComplete + { + get => _onPlaybackComplete; + set + { + _onPlaybackComplete = value; + if (_audioPlayer != null) + { + _audioPlayer.OnPlaybackComplete += value; + } + } + } + + public bool LoopPlayback + { + get => _loopPlayback; + set + { + _loopPlayback = value; + if (_audioPlayer != null) + { + _audioPlayer.LoopPlayback = value; + } + } + } private const string SupportedAudioExtension = "ogg"; private const float VolumeMultiplier = 0.5f; private AudioPlayer? _audioPlayer; + private bool _loopPlayback; + private Action? _onPlaybackComplete; private bool _disposedValue; public void Load(string audioFile) @@ -18,7 +44,8 @@ public void Load(string audioFile) _audioPlayer = new AudioPlayer(); _audioPlayer.Load($"{audioFile}.{SupportedAudioExtension}"); _audioPlayer.Volume = VolumeMultiplier; - _audioPlayer.LoopPlayback = true; + _audioPlayer.LoopPlayback = LoopPlayback; + _audioPlayer.OnPlaybackComplete += OnPlaybackComplete; } public void Play() => _audioPlayer?.Play(); diff --git a/source/TextBlade.Platform.Windows/TextBlade.Platform.Windows.csproj b/source/TextBlade.Platform.Windows/TextBlade.Platform.Windows.csproj index 7d1dc50..fe7811d 100644 --- a/source/TextBlade.Platform.Windows/TextBlade.Platform.Windows.csproj +++ b/source/TextBlade.Platform.Windows/TextBlade.Platform.Windows.csproj @@ -9,11 +9,10 @@ + - - diff --git a/source/global.json b/source/global.json new file mode 100644 index 0000000..f3cb0dc --- /dev/null +++ b/source/global.json @@ -0,0 +1,5 @@ +{ + "msbuild-sdks": { + "MSBuild.Sdk.Extras": "3.0.44" + } +} \ No newline at end of file