1

I'm creating a webserver on RPI3 that will display the status of the baby(Lying Down, Sitting, Out of the Crib). It will also play a sound notification once the status is "Out of the Crib".

The javasript of my webserver is this:

function notif() {

var pos = $('.status').text();
var audio = new Audio('alarm.mp3');

if(pos == "Out of the crib") {
audio.play();
}

This code is working fine when I access my webserver in different laptop. But when I view my webserver in android webview it does not play the sound, but in different laptop it's working.

Should I do something on my java file in android studio or android webview does not support this kind of thing?

But I tried to add button in my webserver that will play the sound once it's click. And I open it again in my webview and it's working I dont know what to do. Please help. Thank you.

2 Answers2

0

I'm sorry to say but this is a feature not a bug. This is done on purpose to prevent developers from forcing the user to hear/see things without user interaction.

The only thing that you are allowed is to play a muted video without user interaction.

You can override this but only on your device. See this question and the several answers that might help you.

Itamar Kerbel
  • 2,508
  • 1
  • 22
  • 29
-1
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
4b0
  • 21,981
  • 30
  • 95
  • 142
Andy
  • 1
  • 2
    Do not post code-only answers. While your solution may work, answers should also provide some explanation of why the code will resolve the issue raised in the question. – 4b0 Nov 27 '22 at 07:17