Skip to content

Commit

Permalink
Make PlayerView Compose workaround opt-in
Browse files Browse the repository at this point in the history
The workaround causes issues with XML-based shared transitions, so we
can't apply it unilaterally.

Issue: #1594

Issue: #1237
PiperOrigin-RevId: 670960693
  • Loading branch information
icbaker authored and copybara-github committed Sep 4, 2024
1 parent c851464 commit 87bd9ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 18 additions & 2 deletions libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ public interface FullscreenButtonClickListener {
private boolean controllerAutoShow;
private boolean controllerHideDuringAds;
private boolean controllerHideOnTouch;
private boolean enableComposeSurfaceSyncWorkaround;

public PlayerView(Context context) {
this(context, /* attrs= */ null);
Expand Down Expand Up @@ -1304,6 +1305,19 @@ public void setAspectRatioListener(
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:
*
Expand Down Expand Up @@ -1758,7 +1772,7 @@ private void updateAspectRatio() {
@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();
}
}
Expand Down Expand Up @@ -1830,7 +1844,9 @@ public void onVideoSizeChanged(VideoSize videoSize) {

@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)
Expand Down

0 comments on commit 87bd9ba

Please sign in to comment.