Git Product home page Git Product logo

howler.blazor's Introduction

Howler.Blazor

A Blazor JSInterop wrapper for Howler.js.

NuGet: Howler.Blazor

Live Demo

https://stefh.github.io/Howler.Blazor

Usage

Install the NuGet

PM> Install-Package Howler.Blazor

Add the required dependency injections

public void ConfigureServices(IServiceCollection services)
{
+    services.AddScoped<IHowl, Howl>();
+    services.AddScoped<IHowlGlobal, HowlGlobal>();
}

Add the required javascripts to _Host.cshtml

<head>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.1.2/howler.core.min.js" integrity="sha256-q2vnVvwrx3RbYXPyAwx7c2npmULQg2VdCXBoJ5+iigs=" crossorigin="anonymous"></script>
+    <script src="_content/Howler.Blazor/JsInteropHowl.js"></script>
</head>

Use the player

@page "/example"
@using Howler.Blazor.Components

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

<div>
    <button class="btn btn-primary oi oi-media-play" @onclick="Play"></button>
    <button class="btn btn-primary oi oi-media-stop" @onclick="Stop"></button>
    <button class="btn btn-primary oi oi-media-pause" @onclick="Pause"></button>
    <pre>TotalTime : @TotalTime</pre>
    <pre>State : @State</pre>
    <pre>Supported Codes : @SupportedCodes</pre>
</div>

@code {
    protected TimeSpan TotalTime;
    protected string State = "-";
    protected string SupportedCodes;

    protected override async Task OnInitializedAsync()
    {
        // Display all supported codecs
        var codecs = await HowlGlobal.GetCodecs();
        SupportedCodes = string.Join(", ", codecs);

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

            StateHasChanged();
        };

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

            StateHasChanged();
        };

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

            StateHasChanged();
        };
    }

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

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

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

Example Page

Blazor-WebDAV-AudioPlayer

Example project

See

howler.blazor's People

Contributors

chris1411 avatar k-u-s avatar stefh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

howler.blazor's Issues

Need Recording

Could You Please Add Recording functionalities.
Thanks!

Change playback rate

Thanks for creating this wrapper. Its super easy to use. Any plans on implemented the howler rate method for changing the playback rate? I can submit a PR for it but didn't want to duplicate work in case you already had plans for it.

Also, I created a reusable audio player component out of your example that includes a progress bar and timer. I can do a PR for that as well if you like.

Is there a way to make it work with Data URI?

I'm storing the audio files locally in the client with indexeddb as base64 string but I can't figure out how to feed in the Howl the audio data, what I use to make it ingest such data correctly?

Problem getting length of ogg/opus blob on edge

I use your framework inside a blazor application (https://github.com/NeoCoderMatrix86/AudioCuesheetEditor) for editing cuesheets.

If I record some ogg/opus inside the application and play that record with your framework, I get an exception like this:

System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $ | LineNumber: 0 | BytePositionInLine: 4.
 ---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a number.
   at System.Text.Json.Utf8JsonReader.TryGetInt32(Int32& value)
   at System.Text.Json.Utf8JsonReader.GetInt32()
   at System.Text.Json.Serialization.Converters.Int32Converter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Int32& value)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[Object](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadValueCore[Object](JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.ParseArguments(JSRuntime jsRuntime, String methodIdentifier, String arguments, Type[] parameterTypes)
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)

Unable to play Mp3 file from azure blob storage

Hi,
Thanks for this great component. I love the simplicity of integrating it.
I'm getting an error when trying to play an mp3 file from azure storage. Here's the Url:
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

This fails with the error below. I confirmed the file is downloadable and other online players can access it. My sample also works with the urls in Any clues on how to fix this?
Error:
System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $ | LineNumber: 0 | BytePositionInLine: 4. ---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a number.
at System.Text.Json.Utf8JsonReader.TryGetInt32 (System.Int32& value) <0x2136d28 + 0x0001a> in :0
at System.Text.Json.Utf8JsonReader.GetInt32 () <0x2136c58 + 0x00008> in :0
at System.Text.Json.Serialization.Converters.JsonConverterInt32.Read (System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) <0x2136ba8 + 0x00004> in :0
at System.Text.Json.JsonPropertyInfoNotNullable`4[TClass,TDeclaredProperty,TRuntimeProperty,TConverter].OnRead (System.Text.Json.ReadStack& state, System.Text.Json.Utf8JsonReader& reader) <0x21b23f8 + 0x00032> in :0
at System.Text.Json.JsonPropertyInfo.Read (System.Text.Json.JsonTokenType tokenType, System.Text.Json.ReadStack& state, System.Text.Json.Utf8JsonReader& reader) <0x1edbe28 + 0x0007e> in :0
at System.Text.Json.JsonSerializer.HandleNull (System.Text.Json.Utf8JsonReader& reader, System.Text.Json.ReadStack& state) <0x2145490 + 0x00108> in :0
at System.Text.Json.JsonSerializer.ReadCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader, System.Text.Json.ReadStack& readStack) <0x1ec3e20 + 0x00274> in :0
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath (System.Text.Json.ReadStack& readStack, System.Text.Json.Utf8JsonReader& reader, System.Exception ex) <0x22043b8 + 0x00028> in :0
at System.Text.Json.JsonSerializer.ReadCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader, System.Text.Json.ReadStack& readStack) <0x1ec3e20 + 0x0032a> in :0
at System.Text.Json.JsonSerializer.ReadValueCore (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonReader& reader, System.Text.Json.ReadStack& readStack) <0x207ccb8 + 0x00546> in :0
at System.Text.Json.JsonSerializer.ReadValueCore (System.Text.Json.Utf8JsonReader& reader, System.Type returnType, System.Text.Json.JsonSerializerOptions options) <0x207c210 + 0x0003e> in :0
at System.Text.Json.JsonSerializer.Deserialize (System.Text.Json.Utf8JsonReader& reader, System.Type returnType, System.Text.Json.JsonSerializerOptions options) <0x207c130 + 0x00024> in :0
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.ParseArguments (Microsoft.JSInterop.JSRuntime jsRuntime, System.String methodIdentifier, System.String arguments, System.Type[] parameterTypes) <0x210a648 + 0x0015c> in <3eedf0ca90ca4e72bf6870618ca98c7c>:0
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously (Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo& callInfo, Microsoft.JSInterop.Infrastructure.IDotNetObjectReference objectReference, System.String argsJson) <0x20d2120 + 0x00108> in <3eedf0ca90ca4e72bf6870618ca98c7c>:0
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet (Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo invocationInfo, System.String argsJson) <0x20d1c90 + 0x00092> in <3eedf0ca90ca4e72bf6870618ca98c7c>:0
at Object.endInvokeDotNetFromJS (https://localhost:44314/_framework/blazor.webassembly.js:1:9849)
at Object.invokeJSFromDotNet (https://localhost:44314/_framework/blazor.webassembly.js:1:9475)
at _mono_wasm_invoke_js_marshalled (https://localhost:44314/_framework/wasm/mono.js:1:165750)
at wasm-function[6221]:0x11936a
at wasm-function[1431]:0x402ee
at wasm-function[636]:0x147cf
at wasm-function[4996]:0xeb135
at wasm-function[3247]:0xa0666
at wasm-function[1324]:0x3af33
at wasm-function[436]:0xd450

Howl.Seek() does not work as expected

Calling Howl.Seek(TimeSpan) does not seek to the expected position - instead, it essentially restarts the audio clip from the beginning.

I believe that the code below should use position.TotalMilliseconds rather than position.TotalSeconds?

public ValueTask Seek(int soundId, TimeSpan position)
{
    return _runtime.InvokeVoidAsync("howl.seek", soundId, position.TotalSeconds);
}

How can I play local media?

I have a app on RaspberryPi,
how can i play local files?

my files are in storage and i play it with bass.dll on rpi,
but i will play on client side:

this i my data-string:
"/media/New Rock Party/1The 80s.mp3"

Howl.GetTotalTime not only when playback

I would like to have the current total time of an audio file, even when it is not played (and has never been played). Is it possible to grab some metadata when the file has been loaded?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.