我尝试了此博客 (http://android-er.blogspot.kr/2013/05/get-current-frame-in-videoview-using.html) 中的以下教程,其中展示了如何使用 MediaMetadataRetriever 从视频源捕获视频帧。 但是,只有当视频位于手机本地时它才有效。
有没有办法在 VideoView 正在通过 IP 流式传输视频 时捕获视频帧?
最佳答案
Video View是SurfaceView的子类,所以Pixel Copy也可以对video View进行截图
把这个方法放在一些Util类中
/**
* Pixel copy to copy SurfaceView/VideoView into BitMap
*/
fun usePixelCopy(videoView: SurfaceView, callback: (Bitmap?) -> Unit) {
val bitmap: Bitmap = Bitmap.createBitmap(
videoView.width,
videoView.height,
Bitmap.Config.ARGB_8888
);
try {
// Create a handler thread to offload the processing of the image.
val handlerThread = HandlerThread("PixelCopier");
handlerThread.start();
PixelCopy.request(
videoView, bitmap,
PixelCopy.OnPixelCopyFinishedListener { copyResult ->
if (copyResult == PixelCopy.SUCCESS) {
callback(bitmap)
}
handlerThread.quitSafely();
},
Handler(handlerThread.looper)
)
} catch (e: IllegalArgumentException) {
callback(null)
// PixelCopy may throw IllegalArgumentException, make sure to handle it
e.printStackTrace()
}
}
用法:
usePixelCopy(videoView) { bitmap: Bitmap? ->
processBitMp(bitmap)
}
关于android - 如何在Android中捕获VideoView的屏幕截图或视频帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27434087/