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

Media 3 Exoplayer bug fix (Android 14 / API 34) #44

Closed
ryanw-mobile opened this issue May 2, 2024 · 16 comments · Fixed by #76
Closed

Media 3 Exoplayer bug fix (Android 14 / API 34) #44

ryanw-mobile opened this issue May 2, 2024 · 16 comments · Fixed by #76
Assignees
Labels
fix A bug fix for the user, not a fix to a build script.

Comments

@ryanw-mobile
Copy link
Owner

We should have got most of the PIP implementation right, but we'd better follow the official doc for every minor step to make sure the implementation is right and stick to the recommendations.

On Pixel 7 the player looks to scale the video 1:1 then crop 50% vertically. That's a sign shown when we disabled the control display.

@ryanw-mobile ryanw-mobile added the fix A bug fix for the user, not a fix to a build script. label May 2, 2024
@ryanw-mobile ryanw-mobile self-assigned this May 2, 2024
@ryanw-mobile
Copy link
Owner Author

Exact issue:
androidx/media#1270

Which seems to be related to the calculated video width & height does not match the actual one.

@ryanw-mobile ryanw-mobile changed the title PIP Code Review and player bug fix Media 3 Exoplayer bug fix (Android 14 / API 34) May 3, 2024
@ryanw-mobile
Copy link
Owner Author

Emulator: Pixel 7 - API 33 - Correct Output

Sequence: ZOOM, FIXED_WIDTH, FIXED_HEIGHT, FIT, FILL

API33_RESIZE_MODE_ZOOM API33_RESIZE_MODE_FIXED_WIDTH API33_RESIZE_MODE_FIXED_HEIGHT API33_RESIZE_MODE_FIT API33_RESIZE_MODE_FILL

Emulator: Pixel 7 - API 34 - Distorted Output

API34_RESIZE_MODE_ZOOM API34_RESIZE_MODE_FIXED_WIDTH API34_RESIZE_MODE_FIXED_HEIGHT API34_RESIZE_MODE_FIT API34_RESIZE_MODE_FILL

Emulator: Pixel 7 - VanillaIceCream

V_RESIZE_MODE_ZOOM V_RESIZE_MODE_FIXED_WIDTH V_RESIZE_MODE_FIXED_HEIGHT V_RESIZE_MODE_FIT V_RESIZE_MODE_FILL

@fresnohernandez99
Copy link

facing same issue here

@ryanw-mobile
Copy link
Owner Author

facing same issue here

I could see the player worked a few times by only keeping the basic code to set up the player. However, the result was inconsistent and sometimes did not work. I tried to forcefully invalidate the view (because, obviously, it is due to the player getting the wrong screen dimensions) but could not fix it.

As I mentioned in the Google's issue ticket - since the same piece of code and the library worked on previous Android versions, it can be difficult to say our code / the exoplayer has a bug. If that's due to OS changes, it can be difficult for us to fix/diagnose.

Right now, I can only leave this issue open.

@fresnohernandez99
Copy link

For me it work with a condition. If i'll use RESIZE_MODE_FIXED_WIDTH for example i have to set the container with fillMaxWidth() and not fillMaxSize()

@RyeGordo
Copy link

RyeGordo commented Jun 3, 2024

I'm having the same issue with stretched video; additionally, for me it seems like resizeMode is ignored as there is no change in behaviour.

@ryanw-mobile
Copy link
Owner Author

ryanw-mobile commented Jun 7, 2024

I'm having the same issue with stretched video; additionally, for me it seems like resizeMode is ignored as there is no change in behaviour.

For this code base, I have been able to confirm two findings:

  1. It is running fine on API 33. The same piece of code doesn't work on API 34+ - so it is debatable to say my code is incorrect.
  2. I have set the controller to hide when the player starts. When I tap on the player to show the controller, the video resizes properly automatically. This looks to me like the player did not have the correct screen size to start with, and later when it had to invalidate the layout (and get the screen size again), it worked properly as it got the correct screen size for scaling.

Therefore, I believe something is wrong when the player tries to get/calculate the view's screen size on API 34+. If there is a bug, it might be a compose/ other OS bug rather than the exoplayer library's since, again, the same player works well on API 33. This makes it difficult to investigate further.

Another possibility might be due to my complex activity setup—I use Single Activity to implement the player and PIP, so it might be my fault for accidentally overriding some configuration changes. I plan to comment out all other extra features in my project to see if the player would work again.

@ryanw-mobile
Copy link
Owner Author

Tested again by elevating media3 to 1.4.0-alpha02. As expected, this does not solve the problem.

@ryanw-mobile ryanw-mobile pinned this issue Jun 12, 2024
@ryanw-mobile
Copy link
Owner Author

We are getting closer to the root cause (that Google has yet face the reality):
AspectRatioFrameLayout problem
"there seems to be another cause of the issue that was introduced on the 5th, March 2024, that is somehow correlated to hardware acceleration, Jetpack Compose, and Google Pixel phones."

Video is cut on the edge when using Compose and uses RESIZE_MODE_ZOOM - Only Android 14

@ryanw-mobile
Copy link
Owner Author

Root cause identified. The workaround will be available in media3 1.4.0-rc01 .

We don't have access to SurfaceSyncGroupCompatV34, so we cannot apply locally a patched PlayerView.java, so it's better to wait until 1.4.0-rc01 is available.

androidx/media#1237 (comment)

I've updated the title of this issue to reflect that this isn't specific to AspectRatioFrameLayout, and it's more related to SurfaceView inside a Compose AndroidView on Android 14.

With the support of the graphics team, I've also submitted a workaround (linked above) to PlayerView, which resolves this issue for users of this class. This will be included in 1.4.0-rc01. I'm going to close this issue, since that should resolve the issue for users of media3's UI components. Those who have written their own UI components may be able to adopt a similar workaround.

@RyeGordo
Copy link

I'm glad you found the issue and look forward to this workaround.

Thanks for your efforts regarding this.

@ryanw-mobile ryanw-mobile linked a pull request Jul 13, 2024 that will close this issue
@ryanw-mobile ryanw-mobile unpinned this issue Jul 13, 2024
ryanw-mobile added a commit that referenced this issue Jul 13, 2024
…-android-14

(#44) media 3 exoplayer bug android 14
@RyeGordo
Copy link

The update to 1.4.0-rc01 did not seem to fix my scaling issues; however, I noticed that my videoScalingMode was set to VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING. Changing it to VIDEO_SCALING_MODE_SCALE_TO_FIT seems to fix my scaling issue.

@ryanw-mobile
Copy link
Owner Author

The update to 1.4.0-rc01 did not seem to fix my scaling issues; however, I noticed that my videoScalingMode was set to VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING. Changing it to VIDEO_SCALING_MODE_SCALE_TO_FIT seems to fix my scaling issue.

But you still need 1.4.0-rc01 with VIDEO_SCALING_MODE_SCALE_TO_FIT to make it work, right?

@RyeGordo
Copy link

RyeGordo commented Jul 14, 2024

Setting VIDEO_SCALING_MODE_SCALE_TO_FIT while remaining on the previous 1.3.1 version fixes my issue.
The update to 1.4.0-rc01 does not seem to have any impact.

@jiahaoBCN
Copy link

Same here. I have the same issue with the version 1.4.0-rc01 than with 1.3.1. I don't see this problem on the physical Samsung device I have, but as soon I am running it on the emulator with Pixel 7 or Pixel 8, with Android 14, some black band will appear on the right side and the bottom of the video.

Btw, this problem happens only with 2 of the sample video I am working with. It does not happen with a third video with better quality. Maybe it is because the video couldn't stretch to the whole screen?

I am wrapping the player over a vertical view pager. Another interesting finding is that while the video of the first page works fine, when I scroll down and scroll up (go to another video and go back to it again), the same video will resize and shrink.

@ryanw-mobile
Copy link
Owner Author

Same here. I have the same issue with the version 1.4.0-rc01 than with 1.3.1. I don't see this problem on the physical Samsung device I have, but as soon I am running it on the emulator with Pixel 7 or Pixel 8, with Android 14, some black band will appear on the right side and the bottom of the video.

Btw, this problem happens only with 2 of the sample video I am working with. It does not happen with a third video with better quality. Maybe it is because the video couldn't stretch to the whole screen?

I am wrapping the player over a vertical view pager. Another interesting finding is that while the video of the first page works fine, when I scroll down and scroll up (go to another video and go back to it again), the same video will resize and shrink.

Thank you for your sharing.

However, this is not a place to report any issues if you believe the root cause is different. I would suggest you report it back to Google for your case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix A bug fix for the user, not a fix to a build script.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants