Play sound in Blazor Hybirs app

Qun Shen 60 Reputation points
2024-04-23T10:01:01.01+00:00

I have a blazor hybird app running Android emulator inViual Studio. the app has a button when clicked play a sound using javascript interop to play a soun. the js code :

window.PlayAudio = (elementName) => {

document.getElementById(elementName).play();
```}

and c# code:

<button type="button" @onclick="Play" class="btn btn-primary">Play</button>

 public void Play()

 {

m_jsRuntime.InvokeAsync<string>("PlayAudio", "notification");

StateHasChanged();


The code works well in browser and no sound played in Blazor Hybird maui app.

 thanks for your help!

Developer technologies | .NET | Blazor
Developer technologies | .NET | .NET MAUI
Developer technologies | .NET | Other
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2024-04-24T09:03:42.63+00:00

    Hello,

    This issue is related to the Emulator, if you run your application to the Android physical devices. You can hear the voice when video is playing.

    Then I found emulator's sound is closed by default.

    You need to press the top volume button underneath the power icon. Then click the three dots.

    Untitled1

    Next, click the settings, in this step, you can hear the clicking sound and set the media volume to the max.

    Untitled2

    After that, you can run your application to hear the video's sound.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.