Skip to content

YouTube player does not size itself properly on API 28 #1230

@musa211

Description

@musa211

Bug Report

Description of the Bug

On my API 28 emulator I noticed that the YouTube embed player appears zoomed in, only the top right quadrant of the video is visible. In the screenshot below, the center message is a youtube video.

Image

Environment details

Android Version: 9
API Version: 28

Tested devices:
Android Studio Emulator Pixel 2 API 28
Android Studio Emulator Pixel 3 API 28

Youtube Player Library Version: 12.1.2

Steps to reproduce the bug

  1. Use Android Studio Emulator device with API 28
  2. Programmatically create YoutubePlayer
  3. Add to ViewGroup (LinearLayout) which lies in a RecyclerView
  4. Run the application on the targeted device (as mentioned earlier)
  5. Navigate to that YoutubePlayer on the emulator
  6. Observe the player is zoomed in and only shows the top right quadrant
  7. Video is still clickable and you can hear audio in the background

What I've tried

  • Tested on APIs above 28 to see if it's an isolate case to level 28 (same code works normally on 29+)
  • Set layout parameters to MATCH_PARENT, WRAP_CONTENT for width and height respectively, and set margins and paddings to 0
  • Confirmed hardwareAccelerated is set to true

Additional information

When navigating to player When clicked on Works on Pixel3 with API 29
Image Image Image

Relevant codeblock

        val youTubePlayerView = YouTubePlayerView(view.context).apply {
            enableAutomaticInitialization = false
        }
        val iFramePlayerOptions = IFramePlayerOptions.Builder()
            .rel(0)
            .autoplay(0)
            .controls(1)
            .build()
        val youTubePlayerListener = object : AbstractYouTubePlayerListener() {
            override fun onReady(youTubePlayer: YouTubePlayer) {
                youTubePlayer.cueVideo(videoId, 0f)
                youTubePlayerView.visibility = View.VISIBLE
            }

            override fun onError(youTubePlayer: YouTubePlayer, error: PlayerConstants.PlayerError) {
                youTubePlayerView.visibility = View.GONE
                super.onError(youTubePlayer, error)
            }
        }
        viewGroup.addView(youTubePlayerView)
        youTubePlayerView.initialize(youTubePlayerListener, iFramePlayerOptions)
        lifecycle.addObserver(youTubePlayerView)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions