diff --git a/Promete.Example/examples/audio/ogg_vorbis.cs b/Promete.Example/examples/audio/ogg_vorbis.cs index e559d9e..ba1a89c 100644 --- a/Promete.Example/examples/audio/ogg_vorbis.cs +++ b/Promete.Example/examples/audio/ogg_vorbis.cs @@ -25,6 +25,8 @@ public override void OnUpdate() Location: {audio.Time / 1000f:0.000} / {audio.Length / 1000f:0.000} Location in Samples: {audio.TimeInSamples} / {audio.LengthInSamples} Loaded: {bgm.LoadedSize} / {bgm.Samples} + Is Playing: {audio.IsPlaying} + Is Pausing: {audio.IsPausing} [↑] Volume Up [↓] Volume Down [←] Pitch Down @@ -49,9 +51,13 @@ PRESS ESC TO RETURN if (keyboard.Space.IsKeyDown) { - if (audio.IsPlaying) + if (audio is { IsPlaying: true, IsPausing: false }) { - audio.Stop(); + audio.Pause(); + } + else if (audio.IsPausing) + { + audio.Resume(); } else { diff --git a/Promete/Audio/AudioPlayer.cs b/Promete/Audio/AudioPlayer.cs index 82d6c17..4f16223 100644 --- a/Promete/Audio/AudioPlayer.cs +++ b/Promete/Audio/AudioPlayer.cs @@ -133,6 +133,25 @@ public async void Play(IAudioSource source, int? loop = default) await PlayAsync(source, loop, stopToken); } + /// + /// 一時停止します。 + /// + public void Pause() + { + if (!IsPlaying) return; + IsPausing = true; + } + + /// + /// 一時停止を解除します。 + /// + public void Resume() + { + if (!IsPausing) return; + IsPausing = false; + Console.WriteLine("set IsPausing to false"); + } + /// /// 再生を停止します。 /// @@ -277,6 +296,16 @@ private async ValueTask PlayAsync(IAudioSource source, int? loop, StopTokenSourc await Task.Delay(1).ConfigureAwait(false); + if (IsPausing) + { + al.SourcePause(alSource.Handle); + while (IsPausing) + { + await Task.Delay(1).ConfigureAwait(false); + } + al.SourcePlay(alSource.Handle); + } + // 外部から再生停止が要求された場合、再生を終了する if (st.IsStopRequested) {