Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

How to take a screenshot from youtube player

$
0
0

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.


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>