Skip to content

aosp: Apply the player bounds to the video surface - #13282

Merged
andrewsavage1 merged 2 commits into
youtube:mainfrom
ogarai:yts/fix_aosp_video_surface_bounds
Oct 16, 2026
Merged

andrewsavage1 merged 2 commits into
youtube:mainfrom
ogarai:yts/fix_aosp_video_surface_bounds

Conversation

@ogarai

@ogarai ogarai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

BaseCobaltActivity.setVideoSurfaceBounds() did nothing on AOSP, so the
video always filled the screen, whatever the player's bounds. For
example, Shorts showed a cropped video.

Move Android TV's video surface code from CobaltActivity into
BaseCobaltActivity, so AOSP uses it too. That covers both
setVideoSurfaceBounds() and resetVideoSurface().

Test: Shorts now play in their 608x1080 frame. A 640x360 video
element at 200,150 gets a video layer with the same bounds, and the
layer follows when the element moves. Before, it stayed full screen.
The Android TV Java library builds.

Fixed: 567316237

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
Context State Description
CI / All Pass ⏳ PENDING Checks are running
CI / android ⏳ PENDING Checks are running
CI / evergreen ⏳ PENDING Checks are running
CI / linux ⏳ PENDING Checks are running
CI / tvos ⏳ PENDING Checks are running
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🤖 Gemini Suggested Commit Message


android: Apply player bounds to video surface

Implement setVideoSurfaceBounds in the AOSP MainActivity to ensure
video content respects the player's specified dimensions and
position. Previously, this method was a no-op on AOSP, causing
videos to always fill the screen and resulting in cropped content
for features like YouTube Shorts.

Updating the VideoSurfaceView layout parameters ensures the video
layer correctly follows moving elements and maintains the intended
size, matching the behavior on Android TV.

Bug: 567316237

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-commit-message

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates MainActivity to store a reference to VideoSurfaceView and implements setVideoSurfaceBounds to dynamically resize and reposition the video surface on the UI thread. The review feedback highlights a potential race condition in setVideoSurfaceBounds where mVideoSurfaceView might be null when the UI thread runnable executes, and suggests adding a null check to prevent a NullPointerException.

@andrewsavage1 andrewsavage1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note we'll also need to implement resetVideoSurface either here or in a follow-up

@ogarai
ogarai requested a review from a team as a code owner October 14, 2026 18:56
@ogarai

ogarai commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Note we'll also need to implement resetVideoSurface either here or in a follow-up

Done. PTAL at latest change

BaseCobaltActivity.setVideoSurfaceBounds() did nothing on AOSP, so the
video always filled the screen, whatever the player's bounds. For
example, Shorts showed a cropped video.

Move and resize the VideoSurfaceView to the player bounds, as Android
TV does.

Test: Shorts now play in their 608x1080 frame. A 640x360 video
element at 200,150 gets a video layer with the same bounds, and the
layer follows when the element moves. Before, it stayed full screen.

Fixed: 567316237
@ogarai
ogarai force-pushed the yts/fix_aosp_video_surface_bounds branch 2 times, most recently from 2e63b62 to c1ea72d Compare October 14, 2026 19:54

@andrewsavage1 andrewsavage1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One follow-up on the onStart() / onStop() video surface lifecycle handling in CobaltActivity:
CobaltActivity still has two pieces of mVideoSurfaceView logic in onStart() and onStop() that weren't moved to BaseCobaltActivity:

  1. Recreating the surface on start if it wasn't destroyed when stopped (mForceCreateNewVideoSurfaceView in onStop() / onStart()).
  2. Resetting the video surface bounds to fullscreen in onStop():
    View rootView = getWindow().getDecorView();
    setVideoSurfaceBounds(0, 0, rootView.getWidth(), rootView.getHeight());

We probably want to move those into BaseCobaltActivity.onStart() / onStop() as well (probably in a follow-up) so AOSP gets the same behavior when backgrounding/resuming

@andrewsavage1
andrewsavage1 enabled auto-merge (squash) October 15, 2026 18:44
@ogarai

ogarai commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

One follow-up on the onStart() / onStop() video surface lifecycle handling in CobaltActivity: CobaltActivity still has two pieces of mVideoSurfaceView logic in onStart() and onStop() that weren't moved to BaseCobaltActivity:

  1. Recreating the surface on start if it wasn't destroyed when stopped (mForceCreateNewVideoSurfaceView in onStop() / onStart()).
  2. Resetting the video surface bounds to fullscreen in onStop():
    View rootView = getWindow().getDecorView();
    setVideoSurfaceBounds(0, 0, rootView.getWidth(), rootView.getHeight());

We probably want to move those into BaseCobaltActivity.onStart() / onStop() as well (probably in a follow-up) so AOSP gets the same behavior when backgrounding/resuming

Agreed. I can work on it in a follow-up PR. PLMK if that's reasonable.

@ckim1346

Copy link
Copy Markdown
Member

One follow-up on the onStart() / onStop() video surface lifecycle handling in CobaltActivity: CobaltActivity still has two pieces of mVideoSurfaceView logic in onStart() and onStop() that weren't moved to BaseCobaltActivity:

  1. Recreating the surface on start if it wasn't destroyed when stopped (mForceCreateNewVideoSurfaceView in onStop() / onStart()).
  2. Resetting the video surface bounds to fullscreen in onStop():
    View rootView = getWindow().getDecorView();
    setVideoSurfaceBounds(0, 0, rootView.getWidth(), rootView.getHeight());

We probably want to move those into BaseCobaltActivity.onStart() / onStop() as well (probably in a follow-up) so AOSP gets the same behavior when backgrounding/resuming

Agreed. I can work on it in a follow-up PR. PLMK if that's reasonable.

LGTM w/ a +1 to this

@andrewsavage1
andrewsavage1 merged commit 2e63208 into youtube:main Oct 16, 2026
556 of 852 checks passed
cobalt-github-releaser-bot pushed a commit that referenced this pull request Oct 16, 2026
…face

Refer to original PR: #13282

BaseCobaltActivity.setVideoSurfaceBounds() did nothing on AOSP, so the
video always filled the screen, whatever the player's bounds. For
example, Shorts showed a cropped video.

Move Android TV's video surface code from CobaltActivity into
BaseCobaltActivity, so AOSP uses it too. That covers both
setVideoSurfaceBounds() and resetVideoSurface().

Test: Shorts now play in their 608x1080 frame. A 640x360 video
element at 200,150 gets a video layer with the same bounds, and the
layer follows when the element moves. Before, it stayed full screen.
The Android TV Java library builds.

Fixed: 567316237

(cherry picked from commit 2e63208)
briantting pushed a commit that referenced this pull request Oct 20, 2026
…face

Refer to original PR: #13282

BaseCobaltActivity.setVideoSurfaceBounds() did nothing on AOSP, so the
video always filled the screen, whatever the player's bounds. For
example, Shorts showed a cropped video.

Move Android TV's video surface code from CobaltActivity into
BaseCobaltActivity, so AOSP uses it too. That covers both
setVideoSurfaceBounds() and resetVideoSurface().

Test: Shorts now play in their 608x1080 frame. A 640x360 video
element at 200,150 gets a video layer with the same bounds, and the
layer follows when the element moves. Before, it stayed full screen.
The Android TV Java library builds.

Fixed: 567316237

(cherry picked from commit 2e63208)
briantting pushed a commit that referenced this pull request Oct 20, 2026
…face

Refer to original PR: #13282

BaseCobaltActivity.setVideoSurfaceBounds() did nothing on AOSP, so the
video always filled the screen, whatever the player's bounds. For
example, Shorts showed a cropped video.

Move Android TV's video surface code from CobaltActivity into
BaseCobaltActivity, so AOSP uses it too. That covers both
setVideoSurfaceBounds() and resetVideoSurface().

Test: Shorts now play in their 608x1080 frame. A 640x360 video
element at 200,150 gets a video layer with the same bounds, and the
layer follows when the element moves. Before, it stayed full screen.
The Android TV Java library builds.

Fixed: 567316237

(cherry picked from commit 2e63208)
@ogarai
ogarai deleted the yts/fix_aosp_video_surface_bounds branch November 4, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants