Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Loop to HowlOptions #15

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.9.6-preview-01</VersionPrefix>
<VersionPrefix>0.9.6</VersionPrefix>
</PropertyGroup>

<Choose>
Expand Down
18 changes: 18 additions & 0 deletions examples/Howler.Blazor-AudioPlayer/Pages/Example.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<td><button class="btn btn-primary oi oi-media-play" @onclick="Play3"></button></td>
<td>Play an audio file with source location and format</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-play" @onclick="PlayLoop"></button></td>
<td>Play and loop an audio file</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-pause" @onclick="Pause"></button></td>
<td>Pause</td>
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions examples/Howler.Blazor-WASM-AudioPlayer-NET5/Pages/Example.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<td><button class="btn btn-primary oi oi-media-play" @onclick="Play3"></button></td>
<td>Play an audio file with source location and format</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-play" @onclick="PlayLoop"></button></td>
<td>Play and loop an audio file</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-pause" @onclick="Pause"></button></td>
<td>Pause</td>
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions examples/Howler.Blazor-WASM-AudioPlayer/Pages/Example.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<td><button class="btn btn-primary oi oi-media-play" @onclick="Play3"></button></td>
<td>Play an audio file with source location and format</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-play" @onclick="PlayLoop"></button></td>
<td>Play and loop an audio file</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-pause" @onclick="Pause"></button></td>
<td>Pause</td>
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/Howler.Blazor/Components/HowlOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public bool Html5 { get; set; }
public bool Html5 { get; set; }

/// <summary>
/// Set to true to automatically loop the sound forever.
/// </summary>
public bool Loop { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Howler.Blazor/wwwroot/JsInteropHowl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down