I have a fragment with a WebView
that loads a YouTube link.
ex. https://www.youtube.com/watch?v=CeNMOYuICcM.
In the fragment's onPause
, I added this to prevent the playback when the screen is not displayed:
webView.onPause();
webView.pauseTimers();
Then in the fragment's onResume
, I added this to allow playback when the screen is re-displayed:
webView.onResume();
webView.resumeTimers();
(This is based on other SO posts such as this and this).
My concern is when I do the following steps:
- Tap Play on the YouTube video
- Send the app to background
- Wait for some time
- Return to the app
If the wait is quick (say 1s), on 4., the video autoplays on its own.
If the wait is long (about 3s or more), on 4., the video does not autoplay.
Why is there a difference?
I already added tried setting setMediaPlaybackRequiresUserGesture
to true
, but the video still autoplays when the wait time is not long enough.
I would like the video to never autoplay.
Is there a way to do that?
Test env:
Nexus 5 5.1.1, Nexus 9 6.0.
Android System WebView 53.0.2785.124.