I came across a problem the other day where I needed to play a sound file in a Blazor WebAssembly application, but there were very limited resources as to how to do this. So, once I figured it out, I also figured that someone else was going to have this problem.
(Even if that person is just me in the future).
Let’s see how to play a sound in Blazor!
As always, there’s a sample project on GitHub that has the code we’re going to write in this post. Check it out!
There are five steps we need the ability to play a sound in Blazor:
<audio>
element.IJSRuntime
injected to our Blazor component.IJSRuntime
to invoke the JavaScript method.#blazor #javascript #webassembly #programming