Open TavernKeeper20 opened 3 years ago
From your message it's not clear what is not working.
I'll try to explain it better this time
So, when the Youtube player is in fullscreen and you click on the back button on your phone, it closes the app. I had similar issue with Webview - when site was loaded and you clicked on an article and then wanted to go back and pressed the back button, the app closed down (not shutdown, but you went to homescreen).
So I added an if statement to the onBackPressed function in my MainActivity.Java like so:
WebView webView = findViewById(R.id.webView); if (webView.canGoBack()) { webView.goBack(); } else{ super.onBackPressed(); }
Now, you can navigate in webView
I want to do the same with the Youtube player. Basically, whenever the player is in fullscreen and the user presses the "back button", currently the app closes down, but I want it to first check if the player is in fullscreen and if it is, have it exit the fullscreen.
To achieve that, I added similar code like so:
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view); if (youTubePlayerView.isFullScreen()) { youTubePlayerView.exitFullScreen(); } else { super.onBackPressed(); }
But it seems to not work and I'm not sure why? My project is in Java and the library is in Kotlin. Can that be what's causing this? I'm not getting any error.
The problem is not with kotlin.
If you enter the else statement, it seems that the player is not actually fullscreen. You can put a breakpoint inside YouTubePlayerView to double check what's happening.
How do I listen to fullscreen button?
Here's my code:
I bring in the reference from XML:
Then the "If" statements:
Here's my YT player in XML: