Skip to content

[camerax] function passed in startImageStream is not executed when image stream is stopped once. #130005

@jedymatt

Description

@jedymatt

Is there an existing issue for this?

Steps to reproduce

  1. Add these in pubspect.yaml
    camera: ^0.10.5+2
    camera_android_camerax: ^0.5.0+7
  2. Paste the code sample provided

Expected results

startImageStream's provided function should be called even after stopping it once.

Actual results

startImageStream doesn't call the function after stopping the image stream. The startImageStream did get executed but not the function provided (controller.value.isStreamingImages). In the code sample, it didn't print again.

Code sample

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

late final List<CameraDescription> cameras;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  cameras = await availableCameras();
  runApp(CameraApp());
}

class CameraApp extends StatefulWidget {
  const CameraApp({super.key});

  @override
  State<CameraApp> createState() => _CameraAppState();
}

class _CameraAppState extends State<CameraApp> {
  late CameraController controller;

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

    controller = CameraController(
      cameras[0],
      ResolutionPreset.low,
      enableAudio: false,
    );

    controller.initialize().then((_) {
      if (!mounted) {
        return;
      }
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: CameraPreview(controller),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            if (controller.value.isStreamingImages) {
              print('>>> stopping');
              controller.stopImageStream();
            } else {
              print('>>> starting');
              controller.startImageStream((image) {
                print('>>> streaming');
              });
            }

            setState(() {});
          },
          child: Icon(
            controller.value.isStreamingImages ? Icons.pause : Icons.play_arrow,
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
Showing Android SDK built for x86 logs:
I/flutter (13994): The Dart VM service is listening on http://127.0.0.1:38398/XaDiRZ5DR-g=/
I/flutter (13994): >>> starting
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> streaming
I/flutter (13994): >>> stopping
I/flutter (13994): >>> starting

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1928], locale en-PH)
    • Flutter version 3.10.5 on channel stable at C:\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (3 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\Users\jedym\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: C:\Users\jedym\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\222.4459.24.2221.10121639\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.6.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.6.33815.320
    • Windows 10 SDK version 10.0.22000.0

[✓] Android Studio (version 2022.2)
    • Android Studio at C:\Users\jedym\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\222.4459.24.2221.10121639
    • Flutter plugin version 74.0.2
    • Dart plugin version 222.4582
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[✓] VS Code (version 1.79.2)
    • VS Code at C:\Users\jedym\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.68.0

[✓] Connected device (4 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 8.1.0 (API 27) (emulator)
    • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [Version 10.0.22621.1928]
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 114.0.5735.199
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 114.0.1823.43

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listfound in release: 3.10Found to occur in 3.10found in release: 3.12Found to occur in 3.12has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions