From 3ac027f510f083f30cfc1fbfd741c519ff9522d4 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 18 May 2021 18:20:55 +0200 Subject: [PATCH] Loop (#15) --- Directory.Build.props | 2 +- .../Pages/Example.razor | 18 ++++++++++++++++++ .../Pages/Example.razor | 18 ++++++++++++++++++ .../Pages/Example.razor | 18 ++++++++++++++++++ src/Howler.Blazor/Components/HowlOptions.cs | 7 ++++++- src/Howler.Blazor/wwwroot/JsInteropHowl.js | 2 ++ 6 files changed, 63 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 6946f82..71230f0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ - 0.9.6-preview-01 + 0.9.6 diff --git a/examples/Howler.Blazor-AudioPlayer/Pages/Example.razor b/examples/Howler.Blazor-AudioPlayer/Pages/Example.razor index 0b6533a..64cffa8 100644 --- a/examples/Howler.Blazor-AudioPlayer/Pages/Example.razor +++ b/examples/Howler.Blazor-AudioPlayer/Pages/Example.razor @@ -19,6 +19,10 @@ Play an audio file with source location and format + + + Play and loop an audio file + Pause @@ -152,6 +156,20 @@ SoundIds.Add(await Howl.Play(options)); } + protected async Task PlayLoop() + { + ErrorMessage = string.Empty; + Rate = 1.0; + + var options = new HowlOptions + { + Sources = new[] { "https://stefsapublic.blob.core.windows.net/test/ding.mp3" }, + Loop = true + }; + + SoundIds.Add(await Howl.Play(options)); + } + protected async Task Stop() { foreach (int id in SoundIds) diff --git a/examples/Howler.Blazor-WASM-AudioPlayer-NET5/Pages/Example.razor b/examples/Howler.Blazor-WASM-AudioPlayer-NET5/Pages/Example.razor index 0b6533a..64cffa8 100644 --- a/examples/Howler.Blazor-WASM-AudioPlayer-NET5/Pages/Example.razor +++ b/examples/Howler.Blazor-WASM-AudioPlayer-NET5/Pages/Example.razor @@ -19,6 +19,10 @@ Play an audio file with source location and format + + + Play and loop an audio file + Pause @@ -152,6 +156,20 @@ SoundIds.Add(await Howl.Play(options)); } + protected async Task PlayLoop() + { + ErrorMessage = string.Empty; + Rate = 1.0; + + var options = new HowlOptions + { + Sources = new[] { "https://stefsapublic.blob.core.windows.net/test/ding.mp3" }, + Loop = true + }; + + SoundIds.Add(await Howl.Play(options)); + } + protected async Task Stop() { foreach (int id in SoundIds) diff --git a/examples/Howler.Blazor-WASM-AudioPlayer/Pages/Example.razor b/examples/Howler.Blazor-WASM-AudioPlayer/Pages/Example.razor index 0b6533a..64cffa8 100644 --- a/examples/Howler.Blazor-WASM-AudioPlayer/Pages/Example.razor +++ b/examples/Howler.Blazor-WASM-AudioPlayer/Pages/Example.razor @@ -19,6 +19,10 @@ Play an audio file with source location and format + + + Play and loop an audio file + Pause @@ -152,6 +156,20 @@ SoundIds.Add(await Howl.Play(options)); } + protected async Task PlayLoop() + { + ErrorMessage = string.Empty; + Rate = 1.0; + + var options = new HowlOptions + { + Sources = new[] { "https://stefsapublic.blob.core.windows.net/test/ding.mp3" }, + Loop = true + }; + + SoundIds.Add(await Howl.Play(options)); + } + protected async Task Stop() { foreach (int id in SoundIds) diff --git a/src/Howler.Blazor/Components/HowlOptions.cs b/src/Howler.Blazor/Components/HowlOptions.cs index fc3fe78..94be972 100644 --- a/src/Howler.Blazor/Components/HowlOptions.cs +++ b/src/Howler.Blazor/Components/HowlOptions.cs @@ -19,6 +19,11 @@ public class HowlOptions /// Set to true to force HTML5 Audio. /// This should be used for large audio files so that you don't have to wait for the full file to be downloaded and decoded before playing. /// - public bool Html5 { get; set; } + public bool Html5 { get; set; } + + /// + /// Set to true to automatically loop the sound forever. + /// + public bool Loop { get; set; } } } \ No newline at end of file diff --git a/src/Howler.Blazor/wwwroot/JsInteropHowl.js b/src/Howler.Blazor/wwwroot/JsInteropHowl.js index 7acc630..af34a31 100644 --- a/src/Howler.Blazor/wwwroot/JsInteropHowl.js +++ b/src/Howler.Blazor/wwwroot/JsInteropHowl.js @@ -7,6 +7,8 @@ window.howl = { src: options.sources, format: options.formats, html5: options.html5, + loop: options.loop, + onplay: async function (id) { let duration = howl.duration(id); if (duration === Infinity || isNaN(duration)) {