-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,12 +47,25 @@ | |
<td><button class="btn btn-primary oi oi-arrow-bottom" @onclick="SpeedDown"></button></td> | ||
<td>Speed Down</td> | ||
</tr> | ||
<tr> | ||
<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> | ||
|
@@ -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 = ""; | ||
|
@@ -168,12 +182,13 @@ | |
{ | ||
ErrorMessage = string.Empty; | ||
Rate = 1.0; | ||
Volume = 0.5; | ||
|
||
var options = new HowlOptions | ||
{ | ||
Sources = new[] { "https://lookandstore.blob.core.windows.net/863da396-6e44-4b3b-8db1-e447d87b121f/instrumental_mp3_637141046337946343_99lfo/instrumental_mp3?sv=2018-03-28&sr=b&sig=96LJ7bycF3lrtiWbVP5tK6%2BOOIJKfq7eYPO%2FjOT72ns%3D&se=2022-10-04T18%3A23%3A53Z&sp=rl" }, | ||
Formats = new[] { "mp3" }, | ||
Volume = 0.5 | ||
Volume = Volume | ||
}; | ||
|
||
SoundIds.Add(await Howl.Play(options)); | ||
|
@@ -183,12 +198,13 @@ | |
{ | ||
ErrorMessage = string.Empty; | ||
Rate = 1.0; | ||
Volume = 0.25; | ||
|
||
var options = new HowlOptions | ||
{ | ||
Sources = new[] { "https://lookandstore.blob.core.windows.net/863da396-6e44-4b3b-8db1-e447d87b121f/instrumental_mp3_637141046337946343_99lfo/instrumental_mp3?sv=2018-03-28&sr=b&sig=96LJ7bycF3lrtiWbVP5tK6%2BOOIJKfq7eYPO%2FjOT72ns%3D&se=2022-10-04T18%3A23%3A53Z&sp=rl" }, | ||
Formats = new[] { "mp3" }, | ||
Volume = 0.25 | ||
Volume = Volume | ||
}; | ||
|
||
SoundIds.Add(await Howl.Play(options)); | ||
|
@@ -245,4 +261,24 @@ | |
await Howl.Pause(id); | ||
} | ||
} | ||
private async Task VolumeUp() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe keep the |
||
foreach (int id in SoundIds) | ||
{ | ||
await Howl.Volume(Volume, id); | ||
} | ||
} | ||
|
||
private async Task VolumeDown() | ||
{ | ||
Volume -= 0.1; | ||
// await HowlGlobal.Volume(Volume); | ||
foreach (int id in SoundIds) | ||
{ | ||
await Howl.Volume(Volume, id); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ public ValueTask<int> Play(byte[] audio, string mimetype) | |
|
||
var options = new HowlOptions | ||
{ | ||
Sources = new[] { html5AudioUrl } | ||
Sources = new[] {html5AudioUrl} | ||
}; | ||
|
||
return _runtime.InvokeAsync<int>("howl.play", _dotNetObjectReference, options); | ||
|
@@ -105,6 +105,11 @@ public ValueTask<bool> IsPlaying(int soundId) | |
return _runtime.InvokeAsync<bool>("howl.getIsPlaying", soundId); | ||
} | ||
|
||
public ValueTask<double> Volume(double volume, int soundId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. soundId should be first argument |
||
{ | ||
return _runtime.InvokeAsync<double>("howl.volume", volume, soundId); | ||
} | ||
|
||
public async ValueTask<double> GetRate(int soundId) | ||
{ | ||
return await _runtime.InvokeAsync<double>("howl.getRate", soundId); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,8 @@ public interface IHowl : IHowlEvents | |
ValueTask<TimeSpan> GetTotalTime(int soundId); | ||
|
||
ValueTask<bool> IsPlaying(int soundId); | ||
ValueTask<double> Volume(double volume, int soundId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a newline before |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline after |
||
#endregion | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ public interface IHowlGlobal | |
ValueTask<string[]> GetCodecs(); | ||
|
||
ValueTask<bool> IsCodecSupported(string? extension); | ||
ValueTask Volume(double volume); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add new line before |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,14 @@ window.howl = { | |
|
||
return 0; | ||
}, | ||
volume: function (volume, id) { | ||
const howl = getHowl(id); | ||
if (howl) { | ||
return howl.volume(volume, id); | ||
} | ||
|
||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't return 0 here, that is not needed |
||
}, | ||
destroy: function () { | ||
Object.keys(howlInstances).forEach(key => { | ||
try { | ||
|
@@ -160,7 +168,10 @@ window.howler = { | |
}, | ||
isCodecSupported: function (extension) { | ||
return extension ? Howler._codecs[extension.replace(/^x-/, '')] : false; | ||
} | ||
}, | ||
volume: function (volume) { | ||
Howler.volume(volume); | ||
}, | ||
}; | ||
|
||
function getHowl(id) { | ||
|
There was a problem hiding this comment.
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?