Skip to content

Commit

Permalink
Handle invalid duration in Edge/Chrome (#13)
Browse files Browse the repository at this point in the history
* net5 example

* wip

* .

* .

* stef

* .
  • Loading branch information
StefH committed Feb 10, 2021
1 parent 3f42f15 commit 873b38b
Show file tree
Hide file tree
Showing 39 changed files with 1,680 additions and 538 deletions.
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.4</VersionPrefix>
<VersionPrefix>0.9.5</VersionPrefix>
</PropertyGroup>

<Choose>
Expand Down
2 changes: 1 addition & 1 deletion GitHubReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes

GitHubReleaseNotes.exe --output ReleaseNotes.md --skip-empty-releases --exclude-labels question invalid doc --version 0.9.4
GitHubReleaseNotes.exe --output ReleaseNotes.md --skip-empty-releases --exclude-labels question invalid doc --version 0.9.5
125 changes: 66 additions & 59 deletions Howler.Blazor - Solution.sln
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8A9BC34B-DF33-49C3-AB28-92AEEBD45F84}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B2EEFDB4-1549-4898-95BE-11E3CDBB86DA}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
GitHubReleaseNotes.txt = GitHubReleaseNotes.txt
LICENSE = LICENSE
publish-docs.cmd = publish-docs.cmd
README.md = README.md
ReleaseNotes.md = ReleaseNotes.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Blazor Server App", "Blazor Server App", "{FF14D365-9746-4E03-BF45-927F704C9314}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Howler.Blazor", "src\Howler.Blazor\Howler.Blazor.csproj", "{D3804221-1234-4502-9595-39584E5A0000}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Howler.Blazor-AudioPlayer", "examples\Howler.Blazor-AudioPlayer\Howler.Blazor-AudioPlayer.csproj", "{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Blazor WebAssembly App", "Blazor WebAssembly App", "{38EEA6F0-8208-4415-9CB0-6D4A85AF5419}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Howler.Blazor-WASM-AudioPlayer", "examples\Howler.Blazor-WASM-AudioPlayer\Howler.Blazor-WASM-AudioPlayer.csproj", "{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D3804221-1234-4502-9595-39584E5A0000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3804221-1234-4502-9595-39584E5A0000}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3804221-1234-4502-9595-39584E5A0000}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3804221-1234-4502-9595-39584E5A0000}.Release|Any CPU.Build.0 = Release|Any CPU
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}.Release|Any CPU.Build.0 = Release|Any CPU
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D3804221-1234-4502-9595-39584E5A0000} = {8A9BC34B-DF33-49C3-AB28-92AEEBD45F84}
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B} = {FF14D365-9746-4E03-BF45-927F704C9314}
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01} = {38EEA6F0-8208-4415-9CB0-6D4A85AF5419}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6A8922C-F54E-40FD-B26A-0E636A9EE552}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8A9BC34B-DF33-49C3-AB28-92AEEBD45F84}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B2EEFDB4-1549-4898-95BE-11E3CDBB86DA}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
GitHubReleaseNotes.txt = GitHubReleaseNotes.txt
LICENSE = LICENSE
publish-docs.cmd = publish-docs.cmd
README.md = README.md
ReleaseNotes.md = ReleaseNotes.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Blazor Server App", "Blazor Server App", "{FF14D365-9746-4E03-BF45-927F704C9314}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Howler.Blazor", "src\Howler.Blazor\Howler.Blazor.csproj", "{D3804221-1234-4502-9595-39584E5A0000}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Howler.Blazor-AudioPlayer", "examples\Howler.Blazor-AudioPlayer\Howler.Blazor-AudioPlayer.csproj", "{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Blazor WebAssembly App", "Blazor WebAssembly App", "{38EEA6F0-8208-4415-9CB0-6D4A85AF5419}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Howler.Blazor-WASM-AudioPlayer", "examples\Howler.Blazor-WASM-AudioPlayer\Howler.Blazor-WASM-AudioPlayer.csproj", "{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Howler.Blazor-WASM-AudioPlayer-NET5", "examples\Howler.Blazor-WASM-AudioPlayer-NET5\Howler.Blazor-WASM-AudioPlayer-NET5.csproj", "{F0E4CCFD-02B9-4F63-9875-B182EE3DCE2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D3804221-1234-4502-9595-39584E5A0000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3804221-1234-4502-9595-39584E5A0000}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3804221-1234-4502-9595-39584E5A0000}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3804221-1234-4502-9595-39584E5A0000}.Release|Any CPU.Build.0 = Release|Any CPU
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B}.Release|Any CPU.Build.0 = Release|Any CPU
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01}.Release|Any CPU.Build.0 = Release|Any CPU
{F0E4CCFD-02B9-4F63-9875-B182EE3DCE2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0E4CCFD-02B9-4F63-9875-B182EE3DCE2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0E4CCFD-02B9-4F63-9875-B182EE3DCE2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0E4CCFD-02B9-4F63-9875-B182EE3DCE2C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D3804221-1234-4502-9595-39584E5A0000} = {8A9BC34B-DF33-49C3-AB28-92AEEBD45F84}
{4E9D1FD3-457A-41B2-BE3F-9E5703BD461B} = {FF14D365-9746-4E03-BF45-927F704C9314}
{5B08D736-7BBE-4D4C-80CF-26A71DD36F01} = {38EEA6F0-8208-4415-9CB0-6D4A85AF5419}
{F0E4CCFD-02B9-4F63-9875-B182EE3DCE2C} = {38EEA6F0-8208-4415-9CB0-6D4A85AF5419}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6A8922C-F54E-40FD-B26A-0E636A9EE552}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions examples/Howler.Blazor-WASM-AudioPlayer-NET5/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Howler.Blazor\Howler.Blazor.csproj" />
</ItemGroup>

</Project>
178 changes: 178 additions & 0 deletions examples/Howler.Blazor-WASM-AudioPlayer-NET5/Pages/Example.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
@page "/"
@using Howler.Blazor.Components

<!-- Inject services -->
@inject IHowl Howl
@inject IHowlGlobal HowlGlobal

<div>
<table>
<tr>
<td><button class="btn btn-primary oi oi-media-play" @onclick="PlayLocal"></button></td>
<td>Play a local OGG file</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-play" @onclick="Play1"></button></td>
<td>Play an audio file with source location</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-play" @onclick="Play2"></button></td>
<td>Play an audio file with source location and format</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-pause" @onclick="Pause"></button></td>
<td>Pause</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-media-stop" @onclick="Stop"></button></td>
<td>Stop</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-arrow-top" @onclick="SpeedUp"></button></td>
<td>Speed Up</td>
</tr>
<tr>
<td><button class="btn btn-primary oi oi-arrow-bottom" @onclick="SpeedDown"></button></td>
<td>Speed Down</td>
</tr>
</table>
<br />

<pre>TotalTime : @TotalTime</pre>
<pre>State : @State</pre>
<pre>Playback Rate : @Rate</pre>
<pre>Supported Codes : @SupportedCodes</pre>
<pre>ErrorMessage : @ErrorMessage</pre>
</div>

@code {
private const double MaxRate = 4.0;
private const double MinRate = 0.25;
protected TimeSpan TotalTime;
protected double Rate = 1.0;
protected string State = "-";
protected string SupportedCodes;
public string ErrorMessage = "";

/// <summary>
/// InvalidOperationException: JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendererd. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.
/// </summary>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);

if (firstRender)
{
// Display all supported codecs
var codecs = await HowlGlobal.GetCodecs();
SupportedCodes = string.Join(", ", codecs);

StateHasChanged();
}
}

protected override void OnInitialized()
{
base.OnInitialized();

// Register callbacks
Howl.OnPlay += e =>
{
ErrorMessage = string.Empty;
State = "Playing";
TotalTime = e.TotalTime;

StateHasChanged();
};

Howl.OnStop += e =>
{
State = "Stopped";

StateHasChanged();
};

Howl.OnPause += e =>
{
State = "Paused";

StateHasChanged();
};

Howl.OnRate += e =>
{
Rate = e.CurrentRate;

StateHasChanged();
};

Howl.OnPlayError += e =>
{
ErrorMessage = $"OnPlayError : {e.Error}";

StateHasChanged();
};

Howl.OnLoadError += e =>
{
ErrorMessage = $"OnLoadError : {e.Error}";

StateHasChanged();
};
}

protected async Task PlayLocal()
{
ErrorMessage = string.Empty;
Rate = 1.0;

await Howl.Play("resources/TestRecording.ogg");
}

protected async Task Play1()
{
ErrorMessage = string.Empty;
Rate = 1.0;

await Howl.Play("https://www.healingfrequenciesmusic.com/wp-content/uploads/2015/03/Love-Abounds-Sample.mp3?_=1");
}

protected async Task Play2()
{
ErrorMessage = string.Empty;
Rate = 1.0;

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" }
};
await Howl.Play(options);
}

protected async Task Stop()
{
await Howl.Stop();
}

protected async Task SpeedUp()
{
if (Rate < MaxRate && State == "Playing")
{
await Howl.Rate(Rate + .25);
}
}

protected async Task SpeedDown()
{
if (Rate > MinRate && State == "Playing")
{
await Howl.Rate(Rate - .25);
}
}

protected async Task Pause()
{
await Howl.Pause();
}
}
4 changes: 4 additions & 0 deletions examples/Howler.Blazor-WASM-AudioPlayer-NET5/Pages/Info.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page "/info"
todo

- https://github.com/dotnet/aspnetcore/issues/19796
25 changes: 25 additions & 0 deletions examples/Howler.Blazor-WASM-AudioPlayer-NET5/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Howler.Blazor.Components;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace Howler.Blazor_WASM_AudioPlayer_NET5
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddScoped<IHowl, Howl>();
builder.Services.AddScoped<IHowlGlobal, HowlGlobal>();

await builder.Build().RunAsync();
}
}
}
Loading

0 comments on commit 873b38b

Please sign in to comment.