PierfrancescoSoffritti / android-youtube-player

YouTube Player library for Android and Chromecast, stable and customizable.
https://pierfrancescosoffritti.github.io/android-youtube-player/
MIT License
3.41k stars 757 forks source link

Black screen while playing video #1032

Open chiragtalaviya opened 1 year ago

chiragtalaviya commented 1 year ago

Description of the Bug

It shows black screen while playing video in full screen

Environment details

Android Version: Android 13 API Version: 33

Tested devices:

Youtube Player Library Version: 12.0.0

Steps to reproduce the bug

  1. Create an full screen activity with youtubeplayer
  2. Start the application on the target device
  3. Tap on the video player
  4. See player displaying black screen

Expected behavior

Should play video

Actual behavior

Displaying black screen

PierfrancescoSoffritti commented 1 year ago

Please read the doc and have a look at the sample app. The fullscreen video plays in a separate view.

chiragtalaviya commented 1 year ago

I have already implemented it. WhatsApp Image 2023-07-25 at 7 45 06 PM

PierfrancescoSoffritti commented 1 year ago

I suggest looking at the sample app, and copy the code from there.

Please share a snippet of how you're handling fullscreen.

chiragtalaviya commented 1 year ago
lifecycle.addObserver(binding.youtubePlayerView)

val iFramePlayerOptions: IFramePlayerOptions = IFramePlayerOptions.Builder()
    .controls(1)
    .fullscreen(1)
    .build()

binding.youtubePlayerView.initialize(object : AbstractYouTubePlayerListener() {
    override fun onReady(youTubePlayer: YouTubePlayer) {
        this@FullScreenVideoActivity.youTubePlayer = youTubePlayer
        youTubePlayer.loadVideo(Utils.extractYTId(videoLink), 0f)
    }
}, true, iFramePlayerOptions)

binding.youtubePlayerView.addFullscreenListener(object : FullscreenListener {
    override fun onEnterFullscreen(fullscreenView: View, exitFullscreen: Function0<Unit>) {
        isFullscreen = true

        binding.youtubePlayerView.visibility = View.GONE
        binding.fullScreenViewContainer.visibility = View.VISIBLE
        binding.fullScreenViewContainer.addView(fullscreenView)

        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

    override fun onExitFullscreen() {
        isFullscreen = false

        // the video will continue playing in the player
        binding.youtubePlayerView.visibility = View.VISIBLE
        binding.fullScreenViewContainer.visibility = View.GONE
        binding.fullScreenViewContainer.removeAllViews()

        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
    }
})
PierfrancescoSoffritti commented 1 year ago

What about your layout file?

chiragtalaviya commented 1 year ago

image Here it is

PierfrancescoSoffritti commented 1 year ago

Does the fullscreen example work when you run directly the sample app?

chiragtalaviya commented 1 year ago

yes, even my player is working fine in other tablets but in Samsung tablet it showing black screen.

Naguchennai commented 1 year ago

Yes also having same issue some time black screen only ..video not playing

PierfrancescoSoffritti commented 1 year ago

So does the sample app work in your Samsung tablet?

It could be that that specific table has a modified version of Webview.

Naguchennai commented 1 year ago

i have issue with samsung s22 mobile

PierfrancescoSoffritti commented 1 year ago

Have you tried running the sample app?

chiragtalaviya commented 1 year ago

Actually I don't have that tablet. This issue is reported by user.

Naguchennai commented 1 year ago

i think i missed

   @Override
public void onDestroy() {
    super.onDestroy();
    youTubePlayerView.release();
}
zeeshanayaz commented 1 month ago

In your AndroidManifest file, add this line in application tag. This might fix your issue android:hardwareAccelerated="true"