cameraTrack = RtcHelper.instance.getLocalCameraTrack(PreOptionCamera._1080P)
cameraTrack?.let { track ->
track.addPlayView(binding.videoView)
track.startCapture(object : RTCResultListener {
override fun onSuccess() {
LogUtil.d("$TAG, onSuccess: track.startCapture", LOG_TAG)
val publishCustomOptions = PublishCustomOptions(
TrackDesc.TRACK_MAIN.value, null,
mutableListOf(PublishCustomOptions(TrackDesc.TRACK_SUB.value, null, null))
)
RtcHelper.instance.rtcEngine?.publishLocalVideo(
track, publishCustomOptions,
object : RTCResultListener {
override fun onSuccess() {
}
override fun onFail(code: Int) {
ToastUtil.getInstance().showLongToast("发布摄像头流失败")
track.stopCapture()
cameraTrack = null
}
}
)
}
override fun onFail(code: Int) {
ToastUtil.getInstance().showLongToast("打开摄像头失败")
cameraTrack = null
}
})
}
```kotlin
配置细节如下:
```kotlin
val _1080P: PreOptionCamera = PreOptionCamera(
CameraCaptureOptions(
deviceId = "cameraCapMain",
position = CameraCaptureOptions.CamraPosition.FRONT,
facingMode = CameraCaptureOptions.CameraFacingMode.USER,
width = 1920,
height = 1080,
maxFps = 30
),
VideoPublishOptions(
desc = TrackDesc.TRACK_MAIN.value,
codec = CodecType.H264,
maxBitrate = 2000 * 1024,
width = 1920,
height = 1080,
maxFps = 25,
props = null,
simulcasts = mutableListOf(
VideoPublishOptions(
desc = TrackDesc.TRACK_SUB.value,
codec = CodecType.H264,
maxBitrate = 128 * 1024,
width = 320,
height = 180,
maxFps = 25,
props = null,
simulcasts = null
)
)
)
)
val _720P: PreOptionCamera = PreOptionCamera(
CameraCaptureOptions(
deviceId = "cameraCapMain",
position = CameraCaptureOptions.CamraPosition.FRONT,
facingMode = CameraCaptureOptions.CameraFacingMode.USER,
width = 1280,
height = 720,
maxFps = 30
),
VideoPublishOptions(
desc = TrackDesc.TRACK_MAIN.value,
codec = CodecType.H264,
maxBitrate = 900 * 1024,
width = 1280,
height = 720,
maxFps = 25,
props = null,
simulcasts = mutableListOf(
VideoPublishOptions(
desc = TrackDesc.TRACK_SUB.value,
codec = CodecType.H264,
maxBitrate = 128 * 1024,
width = 320,
height = 180,
maxFps = 25,
props = null,
simulcasts = null
)
)
)
)
val _480P: PreOptionCamera = PreOptionCamera(
CameraCaptureOptions(
deviceId = "cameraCapMain",
position = CameraCaptureOptions.CamraPosition.FRONT,
facingMode = CameraCaptureOptions.CameraFacingMode.USER,
width = 640,
height = 480,
maxFps = 30
),
VideoPublishOptions(
desc = TrackDesc.TRACK_MAIN.value,
codec = CodecType.H264,
maxBitrate = 512 * 1024,
width = 640,
height = 480,
maxFps = 25,
props = null,
simulcasts = mutableListOf(
VideoPublishOptions(
desc = TrackDesc.TRACK_SUB.value,
codec = CodecType.H264,
maxBitrate = 128 * 1024,
width = 320,
height = 180,
maxFps = 25,
props = null,
simulcasts = null
)
)
)
)
val _180P: PreOptionCamera = PreOptionCamera(
CameraCaptureOptions(
deviceId = "cameraCapMain",
position = CameraCaptureOptions.CamraPosition.FRONT,
facingMode = CameraCaptureOptions.CameraFacingMode.USER,
width = 320,
height = 180,
maxFps = 30
),
VideoPublishOptions(
desc = TrackDesc.TRACK_MAIN.value,
codec = CodecType.H264,
maxBitrate = 128 * 1024,
width = 320,
height = 180,
maxFps = 25,
props = null,
simulcasts = mutableListOf(
VideoPublishOptions(
desc = TrackDesc.TRACK_SUB.value,
codec = CodecType.H264,
maxBitrate = 128 * 1024,
width = 320,
height = 180,
maxFps = 25,
props = null,
simulcasts = null
)
)
)
)