Skip to content

[camera_web] CameraException: cameraNotReadable, The camera is not readable due to a hardware error that prevented access to the device. #97016

Closed

Description

@saurabh-m-w

I am using camera plugin in flutter web application,its runs perfectly when I run on local server but I deployed application on github pages where sometimes it runs but most of the times it gives an error like "CameraException(cameraNotReadable, The camera is not readable due to a hardware error that prevented access to the device.)"
Screenshot (496)
Here is my code
https://github.com/saurabh-m-w/Blockchain-Based-Property-Registration/blob/main/lib/screens/transferOwnership.dart#L275

Activity

  1. changed the title [-][camera] [camera_web] cameraNotReadable error on flutter web[/-] [+][camera_web] CameraException: cameraNotReadable, The camera is not readable due to a hardware error that prevented access to the device.[/+] on Jan 24, 2022
  2. maheshj01 commented on Jan 24, 2022

    @maheshj01
    Member

    Hi @saurabh-m-w, Thanks for filing the issue. I ran the official example and it seems to work fine. Please make sure the permission is granted and the camera is not being used elsewhere (other apps) on the device.

    Can you please check this deployed sample app https://cameraweb.netlify.app/#/ based on the official sample code and see if this works fine?

    Also, please share the output of flutter doctor -v.

    code sample for the web app
    import 'package:camera/camera.dart';
    import 'package:flutter/material.dart';
    import 'package:video_player/video_player.dart';
    
    void main(List<String> args) {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          home: FlutterTest(),
        );
      }
    }
    
    class FlutterTest extends StatefulWidget {
      const FlutterTest({Key? key}) : super(key: key);
    
      @override
      State<FlutterTest> createState() => _FlutterTestState();
    }
    
    class _FlutterTestState extends State<FlutterTest> {
      CameraController? _cameraController;
      List<CameraDescription>? _availableCameras;
      final ValueNotifier<VideoPlayerController?> videoPlayerController =
          ValueNotifier<VideoPlayerController?>(null);
      VideoPlayerController? videoController;
      bool isLoading = false;
      bool isRecording = false;
    
      @override
      void dispose() {
        // TODO: implement dispose
        videoController!.dispose();
        _cameraController!.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Expanded(
                child: isLoading
                    ? loading()
                    : Center(
                        child: videoController == null
                            ? Text(!isRecording
                                ? 'Please, record a video'
                                : 'Recording')
                            : VideoPlayer(videoController!)),
              ),
              Center(
                child: Padding(
                  padding: const EdgeInsets.symmetric(vertical: 24.0),
                  child: ElevatedButton(
                    onPressed: !isRecording ? recordVideo : pauseVideoRecording,
                    child:
                        Text(isRecording ? 'Stop Video Recording' : 'Record video'),
                  ),
                ),
              ),
            ],
          ),
        );
      }
    
      Widget loading() {
        return const Center(child: CircularProgressIndicator());
      }
    
      Future<void> pauseVideoRecording() async {
        XFile xfile = await _cameraController!.stopVideoRecording();
    
        videoController = VideoPlayerController.network(xfile.path);
    
        await videoController!.initialize().then((value) {
          setState(() {
            isRecording = false;
          });
          videoController!.play();
        });
      }
    
      Future<void> recordVideo() async {
        if (videoController != null) {
          videoController!.dispose();
          videoController = null;
        }
        setState(() {
          isLoading = true;
        });
        _availableCameras ??= await availableCameras();
        _cameraController ??= CameraController(
          _availableCameras!.first,
          ResolutionPreset.max,
        );
        await _cameraController!.initialize();
        setState(() {
          isLoading = false;
        });
    
        await _cameraController!.startVideoRecording();
        setState(() {
          isRecording = true;
        });
      }
    }
    
    flutter doctor -v
    [✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-GB)
        • Flutter version 2.8.1 at /Users/mahesh/Documents/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 77d935af4d (3 weeks ago), 2021-12-16 08:37:33 -0800
        • Engine revision 890a5fca2e
        • Dart version 2.15.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.10.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 60.1.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.63.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.32.0
    
    [✓] Connected device (4 available)
        • Redmi K20 Pro (mobile) • 192.168.1.3:5555                     • android-arm64  • Android 11 (API 30)
        • iPhone 13 Pro (mobile) • 0FA2FB93-2A89-4FDB-8293-DF66188F1E54 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0
          (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.1 21C52 darwin-arm
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 96.0.4664.110
    
    • No issues found!
    
  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 24, 2022
  4. saurabh-m-w commented on Jan 24, 2022

    @saurabh-m-w
    Author

    Yes I am allowing permissions ,sample app also working fine, I think issue is with my code but its working fine on local server but getting error on deployed website.
    Here is my code

        controller =
            CameraController(cameras[0], ResolutionPreset.max, enableAudio: false);
    
        controller.initialize().then((_) {
          cameraInilizing = false;
          if (!mounted) {
            return;
          }
          setState(() {});
        });
    

    I think I should cameras = await availableCameras(); add this in previous screen as given in official sample code.

    flutter doctor -v

        • Flutter version 2.5.0-6.0.pre at C:\flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 225a43d941 (6 months ago), 2021-08-05 11:32:48 -0700
        • Engine revision 07ec4b82c7
        • Dart version 2.14.0 (build 2.14.0-383.0.dev)
    
    [!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
        • Android SDK at C:\Users\shree\AppData\Local\Android\sdk
        X cmdline-tools component is missing
          Run `path/to/sdkmanager --install "cmdline-tools;latest"`
          See https://developer.android.com/studio/command-line for more details.
        X Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Android Studio (version 2020.3)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin can be installed from:
           https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
           https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    
    [√] VS Code, 64-bit edition (version 1.47.3)
        • VS Code at C:\Program Files\Microsoft VS Code
        • Flutter extension can be installed from:
           https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
    
    [√] Connected device (1 available)
        • Chrome (web) • chrome • web-javascript • Google Chrome 97.0.4692.99
    
    ! Doctor found issues in 1 category.```
    
    
  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 24, 2022
  6. maheshj01 commented on Jan 24, 2022

    @maheshj01
    Member

    Thanks for the update @saurabh-m-w, You seem to be on the older version of flutter. Please try upgrading to the latest
    stable 2.8.1 and see if it resolves the issue. If the issue persists please share the complete error logs in a text file. Also if you can create a reproducible code sample from your code that would help to debug the issue.

  7. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 24, 2022
  8. maheshj01 commented on Jan 25, 2022

    @maheshj01
    Member

    @saurabh-m-w was this resolved?

  9. momentum27 commented on Jan 25, 2022

    @momentum27

    Hello please i want know how to set up de size of the web view display ? Or send user-agent to the server of my website ?

  10. maheshj01 commented on Jan 26, 2022

    @maheshj01
    Member

    @hanane9627, How-to questions are best answered on StackOverflow. However webview has a user agent parameter, you could set it like this

    WebView(
        initialUrl: 'somewhere.net',
        userAgent: 'some user agent',
      ),
  11. BessBrahmin commented on Feb 3, 2022

    @BessBrahmin

    I ran into this same error while messing around and testing random stuff. I get it when I run my code with the Debug Chrome Web browser which is launched from Android Studio. Also the sample app (https://cameraweb.netlify.app/#/) will not work when opened with that debug browser. It will ask for permission and once I give it, the camera flashes its activity light and goes dark. Debug log gives the following trace:

     Error: CameraException(cameraNotReadable, The camera is not readable due to a hardware error that prevented access to the device.)
        at Object.throw_ [as throw] (http://localhost:36821/dart_sdk.js:5386:11)
        at camera_web.CameraPlugin.new.availableCameras (http://localhost:36821/packages/camera_web/src/camera_web.dart.lib.js:222:23)
        at availableCameras.throw (<anonymous>)
        at http://localhost:36821/dart_sdk.js:42616:38
        at _RootZone.runBinary (http://localhost:36821/dart_sdk.js:42471:58)
        at _FutureListener.thenAwait.handleError (http://localhost:36821/dart_sdk.js:37046:33)
        at handleError (http://localhost:36821/dart_sdk.js:37652:51)
        at Function._propagateToListeners (http://localhost:36821/dart_sdk.js:37678:17)
        at _Future.new.[_completeError] (http://localhost:36821/dart_sdk.js:37524:23)
        at async._AsyncCallbackEntry.new.callback (http://localhost:36821/dart_sdk.js:37563:31)
        at Object._microtaskLoop (http://localhost:36821/dart_sdk.js:42771:13)
        at _startMicrotaskLoop (http://localhost:36821/dart_sdk.js:42777:13)
        at http://localhost:36821/dart_sdk.js:37905:9
    

    When I try my code in any other browser than the debug chrome it works just fine and so does the sample app. I don't know what is different about the Chrome Debug browser launched from Android studio, but maybe this additional info will help someone else who is having this problem.

  12. Garciconx commented on Feb 10, 2022

    @Garciconx

    I'm facing the same issue, Greetings!

  13. saurabh-m-w commented on Feb 11, 2022

    @saurabh-m-w
    Author

    For me its working fine now,I think this issue is fixed with latest camera_web: ^0.2.1+2 plugin.

  14. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 11, 2022
  15. Garciconx commented on Feb 11, 2022

    @Garciconx

    I'm still facing the same issue, do you use this? ->

    dependency_overrides:
      camera_web: ^0.2.1+2
    

    Did you follow any extra steps to get this working?

    For me its working fine now,I think this issue is fixed with latest camera_web: ^0.2.1+2 plugin.

  16. saurabh-m-w commented on Feb 11, 2022

    @saurabh-m-w
    Author

    I'm still facing the same issue, do you use this? ->

    dependency_overrides:
      camera_web: ^0.2.1+2
    

    Did you follow any extra steps to get this working?

    dependencies:
      flutter:
        sdk: flutter
      camera: ^0.9.4+11
      camera_web: ^0.2.1+2
    

    I am doing like this On Page 1
    List<CameraDescription> camerasList = await availableCameras();
    and passing camerasList to next page2 where I am using camera.

  17. added
    r: solvedIssue is closed as solved
    and removed
    in triagePresently being triaged by the triage team
    on Feb 14, 2022
  18. github-actions commented on Feb 28, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: solvedIssue is closed as solved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions