Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back button is not working properly #26

Open
brinder opened this issue May 6, 2017 · 1 comment
Open

Back button is not working properly #26

brinder opened this issue May 6, 2017 · 1 comment

Comments

@brinder
Copy link

brinder commented May 6, 2017

When the back is pressed from fullscreen while a video is playing, video gets struck.

@Myerden
Copy link

Myerden commented Aug 21, 2017

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;

First Step

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.

Second Step

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)
	{

Third Step

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();
	}
}

https://stackoverflow.com/a/21281249/4133449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants