Open brinder opened 7 years ago
To accomplish this feature, we should simulate the 'exit full screen' click from webView. What I mean, when user press back button , it should exit the fullscreen like clicked the video's fullscreen button. to do this follow these steps;
Embed this javascript code inside your webView element.
<script>
function exitFullScreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
</script>
** this code should be inside the html body tag.
Use boolean value to know if the video is in fullscreen mode.
My activity like this;
public class PostDetailActivity extends AppCompatActivity
implements VideoEnabledWebChromeClient.ToggledFullscreenCallback{
private boolean fullscreen = false;
// some code
in here we save the fullscreen situation
@Override
public void toggledFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
// Your code to handle the full-screen change, for example showing and hiding the title bar. Example:
if (fullscreen)
{
Call this javascript exit function from activity when back button is pressed;
@Override
public void onBackPressed() {
if (fullscreen){
postWebView.loadUrl("javascript:toggleFullScreen()");
fullscreen=false;
//webChromeClient.onHideCustomView();
}
else
{
postWebView.onPause();
super.onBackPressed();
}
}
When the back is pressed from fullscreen while a video is playing, video gets struck.