I have YouTubePlayerView layout in my xml
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView android:id="@+id/youtubePlayer" android:layout_width="match_parent" android:layout_height="match_parent" app:enableAutomaticInitialization="false" tools:ignore="TooDeepLayout" tools:visibility="gone" />
which plays videos from YouTube. I need to somehow implement the ability to take a screenshot for the player.
I tried similar ways with bitmaps
private fun captureScreenshot() { binding.youtubePlayer.isDrawingCacheEnabled = true val bitmap: Bitmap = Bitmap.createBitmap(view.drawingCache) binding.youtubePlayer.isDrawingCacheEnabled = false viewModel.saveScreenshot(bitmap)}private fun captureScreenshot() { val picture = Picture() val canvas = picture.beginRecording(binding.youtubePlayer.width, binding.youtubePlayer.height) binding.youtubePlayer.draw(canvas) picture.endRecording() val bitmap = Bitmap.createBitmap( picture.width, picture.height, Bitmap.Config.ARGB_8888 ) val bitmapCanvas = Canvas(bitmap) bitmapCanvas.drawPicture(picture) viewModel.saveScreenshot(bitmap)}
but in these methods, instead of the correct image, I get just a black screen, please tell me if it is possible to correctly take screenshots for YouTubePlayerView in android.