79407040

Date: 2025-02-02 17:57:57
Score: 0.5
Natty:
Report link

After a long time of try/error and research the solution for this is quite simple. The code is 100% correct but (at least on Android) the audio is blocked. It is blocked because there is no user interaction on the hybridwevview itself but only on the MAUI UI. If I add a button onto the hybridwebview looking like this:

<button id="enableAudioButton">Enable Audio</button>

and add this code into my JavaScript

document.getElementById('enableAudioButton').addEventListener('click', () => {
const audioElement = document.getElementById('audio');
if (audioElement) {
    audioElement.muted = false;
    audioElement.play().then(() => {
        console.log("enableAudioButton Audio is playing.");
    }).catch((error) => {
        console.error("enableAudioButton Error attempting to play audio:", error);
    });
}

and press the button "Enable Audio", the audio works. What I try to do now is to automate the click on the button, which is the next challange.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Ricardo Enrico Jahn