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!

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,396 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,395 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,897 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,656 Reputation points Microsoft Vendor
    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