Skip to content

[camera_avfoundation] stopVideoRecording may wait indefinitely in some cases #132016

@misos1

Description

@misos1

Is there an existing issue for this?

Steps to reproduce

Run test sample.

Expected results

It should continue to update text up to "99 delete".

Actual results

It stops with text "... stop" which means it is indefinitely waiting on stopVideoRecording. This is because stopVideoRecordingWithResult will not send any result if _videoWriter.status is AVAssetWriterStatusUnknown:
https://github.com/flutter/packages/blob/d7ee75ad59ad7bc45e659d0599e935e9e7981ea1/packages/camera/camera_avfoundation/ios/Classes/FLTCam.m#L683-L707

Code sample

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

void main() {
	runApp(const MyApp());
}

class MyApp extends StatelessWidget {
	const MyApp({super.key});
	@override Widget build(BuildContext context) => 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;
	String where = "";
	late CameraController camera_cont;

	@override void dispose() {
		camera_cont.dispose();
		super.dispose();
	}

	@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();
		for(int i = 0; i < 100; i++)
		{
			setState(() => where = "$i start");
			await camera_cont.startVideoRecording();
			setState(() => where = "$i stop");
			final file = await camera_cont.stopVideoRecording();
			setState(() => where = "$i delete");
			await File(file.path).delete();
		}
	}

	@override Widget build(BuildContext context)
	{
		if(loading)return const Center(child: CircularProgressIndicator());
		else return Stack(
			alignment: Alignment.center,
			children: [
				CameraPreview(camera_cont),
				Text(where),
			],
		);
	}
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-x64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions