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.