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 HowlGlobal Volume (With example) #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions examples/Howler.Blazor-WASM-AudioPlayer/Pages/Example.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,25 @@
<td><button class="btn btn-primary oi oi-arrow-bottom" @onclick="SpeedDown"></button></td>
<td>Speed Down</td>
</tr>
<tr>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also update all 3 example projects?
image

<td>
<button class="btn btn-primary oi oi-arrow-top" @onclick="VolumeUp"></button>
</td>
<td>Volume Up</td>
</tr>
<tr>
<td>
<button class="btn btn-primary oi oi-arrow-bottom" @onclick="VolumeDown"></button>
</td>
<td>Volume Down</td>
</tr>
</table>
<br />

<pre>TotalTime : @TotalTime</pre>
<pre>State : @State</pre>
<pre>Playback Rate : @Rate</pre>
<pre>Volume: @Volume</pre>
<pre>Supported Codes : @SupportedCodes</pre>
<pre>ErrorMessage : @ErrorMessage</pre>
</div>
Expand All @@ -62,6 +75,7 @@
private const double MinRate = 0.25;
protected TimeSpan TotalTime;
protected double Rate = 1.0;
private double Volume = 0.5;
protected string State = "-";
protected string SupportedCodes;
public string ErrorMessage = "";
Expand Down Expand Up @@ -245,4 +259,16 @@
await Howl.Pause(id);
}
}
private async Task VolumeUp()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a new line before this method

{
Volume += 0.1;
await HowlGlobal.Volume(Volume);
}

private async Task VolumeDown()
{
Volume -= 0.1;
await HowlGlobal.Volume(Volume);
}

}
7 changes: 6 additions & 1 deletion src/Howler.Blazor/Components/HowlGlobal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using Microsoft.JSInterop;

Expand Down Expand Up @@ -30,5 +30,10 @@ public ValueTask<bool> IsCodecSupported(string? extension)
{
return _runtime.InvokeAsync<bool>("howler.isCodecSupported", extension);
}

public ValueTask Volume(double volume)
{
return _runtime.InvokeVoidAsync("howler.volume", volume);
}
}
}
1 change: 1 addition & 0 deletions src/Howler.Blazor/Components/IHowlGlobal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public interface IHowlGlobal
ValueTask<string[]> GetCodecs();

ValueTask<bool> IsCodecSupported(string? extension);
ValueTask Volume(double volume);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add new line before

}
}
5 changes: 4 additions & 1 deletion src/Howler.Blazor/wwwroot/JsInteropHowl.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ window.howler = {
},
isCodecSupported: function (extension) {
return extension ? Howler._codecs[extension.replace(/^x-/, '')] : false;
}
},
volume: function (volume) {
Howler.volume(volume);
},
};

function getHowl(id) {
Expand Down