6

I'm currently working on an app that plays videos, some native, some HTML5. For the native videos I use ExoPlayer to play the videos but some sources don't provide me with the raw video file so these must be played within a WebView as HTML5 videos. All videos begin playback with their audio muted and if the user unmutes the video I obtain audio focus. This works great with the ExoPlayer videos but the WebView obtains audio focus as soon as video playback begins.

Is there any way to prevent this behavior and instead only obtain the audio focus when the video is unmuted?

jhorvat
  • 375
  • 3
  • 14

2 Answers2

0

Have you tried abandonAudioFocus()? I would try to implement this at the beginning of playback and then requestAudioFocus() whenever he decides to unmute it.

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

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

The muted keyword will start the video with muted audio and controls will enable html5's player controls where user can unmute the audio.

if you don't want to use html's player control. then you can execute the following code from android to unmute the audio when ever you want

Unmute

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

You can execute the above string with this Answer

Sahil Manchanda
  • 8,768
  • 4
  • 35
  • 76