Make PlayerView Compose workaround opt-in

The workaround causes issues with XML-based shared transitions, so we
can't apply it unilaterally.

Issue: androidx/media#1594

Issue: androidx/media#1237
PiperOrigin-RevId: 670960693
This commit is contained in:
ibaker 2024-09-04 07:21:13 -07:00 committed by Copybara-Service
parent c851464063
commit 87bd9ba585
2 changed files with 25 additions and 2 deletions

View File

@ -23,6 +23,13 @@
* IMA extension:
* Session:
* UI:
* Make the stretched/cropped video in
`PlayerView`-in-Compose-`AndroidView` workaround opt-in, due to issues
with XML-based shared transitions. Apps using `PlayerView` inside
`AndroidView` need to call
`PlayerView.setEnableComposeSurfaceSyncWorkaround` in order to opt-in
([#1237](https://github.com/androidx/media/issues/1237),
[#1594](https://github.com/androidx/media/issues/1594)).
* Downloads:
* OkHttp Extension:
* Cronet Extension:

View File

@ -333,6 +333,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
private boolean controllerAutoShow;
private boolean controllerHideDuringAds;
private boolean controllerHideOnTouch;
private boolean enableComposeSurfaceSyncWorkaround;
public PlayerView(Context context) {
this(context, /* attrs= */ null);
@ -1304,6 +1305,19 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
contentFrame.setAspectRatioListener(listener);
}
/**
* Whether to enable a workaround for the Compose {@code AndroidView} and {@link SurfaceView}
* compatibility issue described in <a
* href="https://github.com/androidx/media/issues/1237">androidx/media#1237</a>.
*
* <p>This workaround causes issues with shared element transitions in XML views, so is disabled
* by default (<a href="https://github.com/androidx/media/issues/1594">androidx/media#1594</a>).
*/
@UnstableApi
public void setEnableComposeSurfaceSyncWorkaround(boolean enableComposeSurfaceSyncWorkaround) {
this.enableComposeSurfaceSyncWorkaround = enableComposeSurfaceSyncWorkaround;
}
/**
* Gets the view onto which video is rendered. This is a:
*
@ -1758,7 +1772,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (Util.SDK_INT == 34 && surfaceSyncGroupV34 != null) {
if (Util.SDK_INT == 34 && surfaceSyncGroupV34 != null && enableComposeSurfaceSyncWorkaround) {
surfaceSyncGroupV34.maybeMarkSyncReadyAndClear();
}
}
@ -1830,7 +1844,9 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
@Override
public void onSurfaceSizeChanged(int width, int height) {
if (Util.SDK_INT == 34 && surfaceView instanceof SurfaceView) {
if (Util.SDK_INT == 34
&& surfaceView instanceof SurfaceView
&& enableComposeSurfaceSyncWorkaround) {
// Register a SurfaceSyncGroup to work around https://github.com/androidx/media/issues/1237
// (only present on API 34, fixed on API 35).
checkNotNull(surfaceSyncGroupV34)