Skip to content

[camera]When is recording interrupted by alarm or phone call video is not synchronized with audio #151253

Description

@misos1

Steps to reproduce

  1. run code sample
  2. start recording
  3. make some alarm or phone call happen during recording
  4. stop alarm or phone call
  5. stop video recording and check the result

After you try to stop the alarm or phone call it may often crash due to #132073, you can either try to reproduce it again (and it may need some considerable amount of tries) or use patch from flutter/packages#6901.

Expected results

Video and audio synchronized. Recording should be probably paused during such an event as an alarm or phone call.

Actual results

In the attached video is recording of counting. What is actually recorded here is the screen of the device after step 5. At number 11 in the video the alarm started and at 24 stopped. It can be heard that audio is seemingly properly handled but video just shows a static frame between 11 and 24 and only after those 13 seconds for which alarm sounded continues from 24 and up.

Code sample

Code sample
import "dart:io";
import "package:flutter/material.dart";
import "package:camera/camera.dart";
import "package:video_player/video_player.dart";

void main()
{
	runApp(const MaterialApp(home: MyHomePage()));
}

class MyHomePage extends StatefulWidget
{
	const MyHomePage({super.key});
	@override State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
{
	bool loading = true;
	bool recording = false;
	late CameraController camera_cont;
	String? file;

	@override void initState()
	{
		super.initState();
		init_camera();
	}

	init_camera() async
	{
		final cameras = await availableCameras();
		camera_cont = CameraController(cameras.firstWhere((camera) => camera.lensDirection == CameraLensDirection.back), ResolutionPreset.ultraHigh);
		await camera_cont.initialize();
		setState(() => loading = false);
		await camera_cont.prepareForVideoRecording();
	}

	void record() async
	{
		await camera_cont.startVideoRecording();
		setState(() => recording = true);
	}

	void stop() async
	{
		final f = await camera_cont.stopVideoRecording();
		setState(() => file = f.path);
	}

	@override Widget build(BuildContext context)
	{
		if(loading)return const Center(child: CircularProgressIndicator());
		if(file != null)return VideoPlayer(VideoPlayerController.file(File(file!))..initialize()..setLooping(true)..play());
		return Stack(
			alignment: Alignment.bottomCenter,
			children: [
				CameraPreview(camera_cont),
				if(recording)FilledButton(onPressed: stop, child: const Text("Stop"))
				else FilledButton(onPressed: record, child: const Text("Record")),
			],
		);
	}
}

Screenshots or Video

Screenshots / Video demonstration
test.mov

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-x64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.22Found to occur in 3.22found in release: 3.24Found to occur in 3.24has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions