mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 22:28:41 +00:00
record audio only when video is started
This commit is contained in:
parent
32bdb0115d
commit
aeabd9268f
1 changed files with 8 additions and 3 deletions
|
|
@ -91,7 +91,8 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future selectCamera(int sCameraId, {bool init = false}) async {
|
Future selectCamera(int sCameraId,
|
||||||
|
{bool init = false, bool enableAudio = false}) async {
|
||||||
if (sCameraId >= gCameras.length) return;
|
if (sCameraId >= gCameras.length) return;
|
||||||
if (init) {
|
if (init) {
|
||||||
for (; sCameraId < gCameras.length; sCameraId++) {
|
for (; sCameraId < gCameras.length; sCameraId++) {
|
||||||
|
|
@ -106,9 +107,9 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
controller = CameraController(
|
controller = CameraController(
|
||||||
gCameras[sCameraId],
|
gCameras[sCameraId],
|
||||||
ResolutionPreset.high,
|
ResolutionPreset.high,
|
||||||
enableAudio: await Permission.microphone.isGranted && videoWithAudio,
|
enableAudio: enableAudio,
|
||||||
);
|
);
|
||||||
controller?.initialize().then((_) async {
|
await controller?.initialize().then((_) async {
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -306,6 +307,10 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
|
|
||||||
Future startVideoRecording() async {
|
Future startVideoRecording() async {
|
||||||
if (controller != null && controller!.value.isRecordingVideo) return;
|
if (controller != null && controller!.value.isRecordingVideo) return;
|
||||||
|
if (hasAudioPermission && videoWithAudio) {
|
||||||
|
await selectCamera(cameraId,
|
||||||
|
enableAudio: await Permission.microphone.isGranted && videoWithAudio);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await controller?.startVideoRecording();
|
await controller?.startVideoRecording();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue