使用SurfaceView ,Camera 拍照录像,打开灯光,后台录像,定时长录像,后台拍照,可同时录像拍照,自适应横竖屏的切换 (录像.mp4 , 拍照.jpg)
package com.bmt.realwear.camerasurfaceview
import android.content.Context
import android.content.res.Configuration
import android.graphics.*
import android.hardware.Camera
import android.hardware.Camera.Parameters.FOCUS_MODE_AUTO
import android.media.MediaRecorder
import android.util.AttributeSet
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.view.View
import com.jay.recorders.objectUtils.ToastUtil
import java.io.IOException
/**
* @author: Jeff <15899859876@qq.com>
* @date: 2018-08-03 16:32
* @description: 使用SurfaceView ,Camera 拍照录像,,可同时录像拍照
*/
class CameraSurfaceView : SurfaceView, SurfaceHolder.Callback, Camera.AutoFocusCallback, View.OnClickListener {
private var screenOritation = Configuration.ORIENTATION_PORTRAIT
private var mOpenBackCamera = true
private var mSurfaceHolder: SurfaceHolder? = null
private var mSurfaceTexture: SurfaceTexture? = null
private var mRunInBackground = false
internal var isAttachedWindow = false
private var mCamera: Camera? = null
private var mParam: Camera.Parameters? = null
private var previewBuffer: ByteArray? = null
private var mCameraId: Int = 0
protected var previewformat = ImageFormat.NV21
internal var context: Context? = null
private val isSupportCameraLight: Boolean
get() {
var mIsSupportCameraLight = false
try {
if (mCamera != null) {
val parameter = mCamera!!.parameters
val a = parameter.supportedFlashModes
if (a == null) {
mIsSupportCameraLight = false
} else {
mIsSupportCameraLight = true
}
}
} catch (e: Exception) {
mIsSupportCameraLight = false
e.printStackTrace()
}
return mIsSupportCameraLight
}
private val previewCallback = Camera.PreviewCallback { data, camera ->
if (data == null) {
releaseCamera()
return@PreviewCallback
}
if (cameraState != CameraState.PREVIEW) {
cameraState = CameraState.PREVIEW
if (cameraStateListener != null) {
cameraStateListener!!.onCameraStateChange(cameraState!!)
}
}
mCamera!!.addCallbackBuffer(previewBuffer)
}
protected var cameraState: CameraState? = null
private var cameraStateListener: CameraStateListener? = null
/**
* ___________________________________以下为视频录制模块______________________________________
*/
internal var mediaRecorder = MediaRecorder()
var isRecording = false</