AndroidCamerax视频序列化和传输
创始人
2024-10-06 15:47:08
0
  1. 在build.gradle中添加依赖项
dependencies {
    ...
    implementation 'com.google.android.gms:play-services-vision:20.1.3'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.camera:camera-core:1.1.0-alpha06'
    implementation 'androidx.camera:camera-camera2:1.1.0-alpha06'
    implementation 'androidx.camera:camera-lifecycle:1.1.0-alpha06'
}
  1. 在MainActivity类中声明变量
private lateinit var cameraExecutor: ExecutorService
private lateinit var viewFinder: TextureView
private lateinit var outputDirectory: File
private val REQUEST_CODE_PERMISSIONS = 10
private val REQUIRED_PERMISSIONS = arrayOf(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)
  1. 在onCreate方法中初始化变量和设置TextureView.SurfaceTextureListener
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    viewFinder = findViewById(R.id.view_finder)

    if (allPermissionsGranted()) {
        viewFinder.post { startCamera() }
    } else {
        ActivityCompat.requestPermissions(
            this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS)
    }

    cameraExecutor = Executors.newSingleThreadExecutor()
    outputDirectory = getOutputDirectory()
    viewFinder.surfaceTextureListener = surfaceTextureListener
}
  1. 在startCamera方法中配置CameraX和Preview
private fun startCamera() {
    val previewConfig = PreviewConfig.Builder().apply {
        setTargetResolution(Size(640, 480))
    }.build()

    val preview = Preview(previewConfig)

    preview.setOnPreviewOutputUpdateListener {
        viewFinder.surfaceTexture = it.surfaceTexture
    }

    val videoFile = File(outputDirectory, "video.mp4").apply {
        createNewFile()
    }
    val videoCaptureConfig = VideoCaptureConfig.Builder().apply {
        setTargetResolution(Size(640, 480))
        setTargetRotation(viewFinder.display.rotation)
        setAudio(Audio.ON)
    }.build()

    val videoCapture = VideoCapture(videoCaptureConfig)

    findViewById

相关内容

热门资讯

方针透视!德普之星透视辅助,w... 方针透视!德普之星透视辅助,wpk辅助是真的吗,详细教程!(竟然有挂)-哔哩哔哩;无需打开直接搜索加...
盘点透视"WePok... 盘点透视"WePoker脚本实战效果"开挂(透视)辅助软件(终于懂了我来教教你)盘点透视"WePok...
资料透视!htx矩阵wepok... 资料透视!htx矩阵wepoker辅助,wepoker模拟器哪个好用,可靠技巧(有挂总结)-哔哩哔哩...
曝光透视"WePok... 曝光透视"WePoker德州开挂神器透视"开挂(透视)辅助平台(推荐一款细节方法)曝光透视"WePo...
技法透视!约局吧德州透视,we... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
发现透视"wepok... 发现透视"wepoker能不能透视辅助"开挂(透视)辅助神器(一分钟了解我来教教你)发现透视"wep...
练习透视!wepoker国外版... 您好:这款wepoker国外版透视游戏是可以开挂的,确实是有挂的,很多玩家在这款wepoker国外版...
策略透视!wepoker有透视... 策略透视!wepoker有透视功能吗,pokemmo脚本辅助,黑科技教程(有挂透视)-哔哩哔哩;无需...
课程透视!德州局怎么透视,po... 课程透视!德州局怎么透视,pokemmo免费脚本,总结教程(有挂教程)-哔哩哔哩1、下载安装好德州局...
操作透视!hhpoker免费透... hhpoker免费透视脚本是一款专注玩家量身打造的游戏记牌类型软件,在hhpoker免费透视脚本这款...