android / platform-samples

A collection of samples of different Android OS platform APIs.
https://developer.android.com/about
Apache License 2.0
1.16k stars 251 forks source link

[Bug]: Transformer Demo video is initially clipped after export #172

Closed calren closed 4 months ago

calren commented 5 months ago

Is there an existing issue for this?

In which area is the issue?

General

In a specific sample?

Transformer Video

What happened?

After exporting a video composition, the video played is not properly sized in the video player, and appears clipped.

If you exit the app and come back, the video sizing and positioning is fixed.

This seems like a problem when an exoplayer view is first created without a video set, and when the video is set ExoPlayer doesn't resize and position the video properly.

https://github.com/android/platform-samples/assets/5016806/f33c0989-4d2e-452c-bfb2-0c653d08ecfb

Relevant logcat output

No response

Code of Conduct

calren commented 5 months ago

@droid-girl Any idea why this might be happening? Feels like the code might be missing something in between setting the mediaItem on the exoplayer and preparing exoplayer for playback (https://github.com/android/platform-samples/blob/main/samples/media/video/src/main/java/com/example/platform/media/video/TransformerVideoComposition.kt#L261-L272), but I can't figure out what's missing. Hoping someone on the ExoPlayer team can help debug.

calren commented 5 months ago

From Kristina: Maybe we should try AspectRatioLayout, ie: https://github.com/androidx/media/blob/d833d59124d795afc146322fe488b2c0d4b9af6a/demos/transformer/src/main/res/layout/transformer_activity.xml#L88

I will give this a try and see if the issue persists.

calren commented 5 months ago

I got the issue resolved by:

  1. Putting PlayerView inside AspectRatioFrameLayout

    <androidx.media3.ui.AspectRatioFrameLayout
        android:id="@+id/input_debug_aspect_ratio_frame_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <androidx.media3.ui.PlayerView
            android:id="@+id/media_player"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
    </androidx.media3.ui.AspectRatioFrameLayout>
  2. Explicitly setting aspect ratio in the Activity / Fragment binding.inputDebugAspectRatioFrameLayout.setAspectRatio(16f/9f)

Will submit a PR for this fix.

This doesn't seem very intuitive, so I will explore ways we can make this easier for the developer.

calren commented 5 months ago

After more investigating, this seems to be a Compose-related issue. When the sample was isolated to only use Views (https://github.com/calren/ViewsTransformerExoPlayerDemo), the issue was no longer present.

The Compose issue is being tracked here: https://github.com/androidx/media/issues/1237 . Using the 1.4.0-rc01 version of PlayerView should resolve this issue. Once Media3 1.4.0-rc01 is released, I will update the Media3 dependency and test again.

In the mean time, I don't think we need to merge the fix that involves using AspectRatioFrameLayout, so I will close https://github.com/android/platform-samples/pull/173