Prevent background image in WebView when playing HTML5 video

I am currently working on an application that plays videos, some native, some HTML5. For my native videos, I use ExoPlayer to play the video, but some sources do not provide me with a raw video file, so they should play in WebView as HTML5 video. All videos start playing with the sound muted, and if the user mutes the video, I get audio focus. This works great with ExoPlayer videos, but WebView gets focus audio as soon as the video starts playing.

Is there a way to prevent this behavior and instead get audio focus only when the video is turned off?

+4
source share
2 answers

Have you tried abandoning AudioFocus ()? I would try to implement this at the beginning of playback, and then requestAudioFocus () whenever it decides to disable it.

You can see the official documentation here: https://developer.android.com/reference/android/media/AudioManager.html#abandonAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener)

0
source
<video id="myPlayer" controls muted>
  <source src="Your audio source" type="video/mp4">
  Your browser does not support the video tag.
</video>

The keyword mutedwill start the video with the sound turned off, and controlswill include html5 controls where the user can turn on the sound.

if you do not want to use html player. then you can execute the following code with android to turn on the sound whenever you want

Enable

String s = "var video = document.getElementById('your-video-id');";
       s+="video.muted= false";

0

Source: https://habr.com/ru/post/1694051/


All Articles