Android Question B4XPages - ExoPlayer not full screen after rotation when using android:configChanges

invocker

Active Member
Hi everyone,

I'm using B4XPages. From my main page, I click a button to open a second page that contains an ExoPlayer. I pass an HLS (.m3u8) video URL to the second page, and the video plays correctly.

The problem occurs when I rotate the phone.

  • If I don't add the following line to the manifest, Android recreates the Activity after rotation, and the app returns to the main page.
  • If I do add this line:
SetActivityAttribute(Main, android:configChanges, "keyboardHidden|orientation|screenSize")
the app stays on the player page, which is what I want. However, after rotating the device, the ExoPlayer is no longer full screen and doesn't resize to fit the new orientation.

How can I:

  1. Keep the player page open after device rotation, and
  2. Make ExoPlayer resize correctly so it fills the entire screen in both portrait and landscape?
Any suggestions or examples would be appreciated.
 

Attachments

  • Test.zip
    11.2 KB · Views: 26

invocker

Active Member
Thank you for the example. It works correctly in the sample project, but I couldn't make it work in my project.

The difference is that my app uses B4XPages. The SimpleExoPlayer and SimpleExoPlayerView are declared in Page2, not in B4XMainPage.
B4XMainPage simply creates and shows Page2, and I use a separate FullScreen Activity with the same code from your example.

I changed the fullscreen code to reference the player in Page2:

Dim player As Object = mp.wplayer.player1.As(JavaObject).GetField("player")

where wplayer is my Page2 instance.

I verified that:

  • GetField("player") returns an androidx.media3.exoplayer.ExoPlayerImpl.
  • Both SimpleExoPlayerView controls are androidx.media3.ui.PlayerView.
However, PlayerView.switchTargetView() still fails with:

java.lang.RuntimeException: Method: switchTargetView not matched.

Is there anything special that needs to be done when the player is hosted in another B4XPage instead of B4XMainPage?
 
Upvote 0

invocker

Active Member
My app has only one layout, and I want it to work correctly in both portrait and landscape without creating separate layouts.
Everything works fine when the page is first opened. To keep the current page from being recreated when the device rotates, I added the following to the manifest:
B4X:
SetActivityAttribute(Main, android:configChanges, "keyboardHidden|orientation|screenSize")
This works as expected because the app stays on the current page and the video continues playing. However, after the orientation change, SimpleExoPlayerView does not resize to fill the available space.
 
Upvote 0
Top