Skip to content

[Web]Cannot play recorded videos using camera with video player plugin #100257

Closed

Description

@Alvarocda

I am trying to record and reproduce the recorded video on Flutter Web

I I'm recording videos using the camera plugin.
After finishing recording the video, the plugin returns me a url of type blob.
With the blob url, I'm trying to play the recorded video using the video_player plugin.

But when trying to initialize VideoPlayerController, the following error appears on my console.

Error: Unsupported operation: Infinity
    at Object.throw_ [as throw] (http://localhost:45721/dart_sdk.js:5067:11)
    at Number.[dartx.round] (http://localhost:45721/dart_sdk.js:17853:17)
    at video_player_web._VideoPlayer.new.sendInitialized (http://localhost:45721/packages/video_player_web/video_player_web.dart.lib.js:370:247)
    at http://localhost:45721/packages/video_player_web/video_player_web.dart.lib.js:312:16
    at Object._checkAndCall (http://localhost:45721/dart_sdk.js:5274:16)
    at Object.dcall (http://localhost:45721/dart_sdk.js:5279:17)
    at HTMLVideoElement.<anonymous> (http://localhost:45721/dart_sdk.js:109327:100)

flutter doctor -v output

[✓] Flutter (Channel stable, 2.10.3, on Linux Mint 20.2 5.13.0-35-generic, locale pt_BR.UTF-8)
    • Flutter version 2.10.3 at /mnt/Arquivos/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (2 weeks ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /mnt/Arquivos/Android/Sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = /mnt/Arquivos/Android/Sdk
    • Java binary at: /mnt/Arquivos/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2020.3)
    • Android Studio at /mnt/Arquivos/android-studio
    • Flutter plugin version 63.2.1
    • Dart plugin version 203.8452
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] IntelliJ IDEA Community Edition (version 2021.3)
    • IntelliJ at /mnt/Arquivos/idea-IC-212.5457.46
    • Flutter plugin version 65.2.4
    • Dart plugin version 213.7227

[✓] VS Code (version 1.65.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.36.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Linux Mint 20.2 5.13.0-35-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 99.0.4844.74

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Activity

  1. maheshj01 commented on Mar 17, 2022

    @maheshj01
    Member

    Hi @Alvarocda, Thanks for filing the issue. Please share a minimal and complete reproducible code to investigate further.

    Thanks

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 17, 2022
  3. changed the title [-]Cant reproduce recorded videos using camera and video_player plugins[/-] [+][Web]Cannot play recorded videos using camera with video player plugin[/+] on Mar 17, 2022
  4. Alvarocda commented on Mar 17, 2022

    @Alvarocda
    Author

    Hi @maheshmnj
    Here is a gist with a reproducible code

    I noticed that when the error appears on the console, the video starts playing automatically, I can hear the audio of the recorded video but no image appears

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 17, 2022
  6. maheshj01 commented on Mar 18, 2022

    @maheshj01
    Member

    @Alvarocda thanks for the info, I updated your code sample a bit as below and I was able to reproduce the issue. The recorded video plays fine on the android app But fails to render on the web and audio keeps playing. Reproducible on both stable and the master channel.

      camera: ^0.9.4+16
      video_player: ^2.3.0
      camera_web: ^0.2.1+3
    code sample
    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 (mac)
    [✓] Flutter (Channel stable, 2.10.3, on macOS 12.1 21C52 darwin-arm, locale en-GB)
        • Flutter version 2.10.3 at /Users/mahesh/Documents/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 7e9793dee1 (20 hours ago), 2022-03-02 11:23:12 -0600
        • Engine revision bd539267b4
        • Dart version 2.16.1
        • DevTools version 2.9.2
    
    [✓] 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.2.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 61.2.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.36.0
    
    [✓] Connected device (3 available)
        • Redmi K20 Pro (mobile) • 192.168.1.5:5555 • android-arm64  • Android 11 (API 30)
        • macOS (desktop)        • macos            • darwin-arm64   • macOS 12.1 21C52 darwin-arm
        • Chrome (web)           • chrome           • web-javascript • Google Chrome 99.0.4844.51
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [✓] Flutter (Channel master, 2.13.0-0.0.pre.103, on macOS 12.2.1 21D62 darwin-arm, locale en-GB)
        • Flutter version 2.13.0-0.0.pre.103 at /Users/mahesh/Documents/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 509ddfda5c (7 hours ago), 2022-03-15 21:10:18 -0700
        • Engine revision dc22c4c7fe
        • Dart version 2.17.0 (build 2.17.0-202.0.dev)
        • DevTools version 2.11.4
    
    [✓] 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.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! CocoaPods 1.10.2 out of date (1.11.0 is recommended).
            CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that
            responds to your plugin usage on the Dart side.
            Without CocoaPods, plugins will not work on iOS or macOS.
            For more info, see https://flutter.dev/platform-plugins
          To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for
          instructions.
    
    [✓] 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 61.2.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.36.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-arm64   • macOS 12.2.1 21D62 darwin-arm
        • Chrome (web)    • chrome • web-javascript • Google Chrome 99.0.4844.74
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
  7. added
    platform-webWeb applications specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Mar 18, 2022
  8. 14 remaining items

  9. ditman commented on Apr 1, 2022

    @ditman
    Member

    @haozi5460 that looks like iOS native code, I think that might be a separate issue. This one (seems to) have to do with the camera web plugin recording videos in a format that is not compatible with the video player for web (in the same browser). We don't have access to NSStuff from the web code.

  10. haozi5460 commented on Apr 1, 2022

    @haozi5460

    An additional test is the built-in camera of the iPhone 12 system. After the video is uploaded to the S3 server, it cannot be opened on the Chrome browser. The downloaded video can be played by Safari and the built-in video player of Mac. And can't play on Windows computer

  11. haozi5460 commented on Apr 1, 2022

    @haozi5460
  12. RBSoftwareBR commented on Apr 14, 2022

    @RBSoftwareBR

    Any updates on this? I have the same issue using windows/chrome.

  13. deepak786 commented on Jun 19, 2022

    @deepak786

    I have the same issue but using this solution flutter-team-archive/plugins#3167 (comment) worked for me.

  14. ditman commented on Jul 14, 2022

    @ditman
    Member

    I've posted a PR that should fix this issue: flutter-team-archive/plugins#6101

  15. removed their assignment
    on Oct 20, 2022
  16. balvinderz commented on Jan 5, 2023

    @balvinderz
    Contributor

    this can be closed.

  17. maheshj01 commented on Jan 5, 2023

    @maheshj01
    Member

    I can confirm that this is fixed. The deployed app https://cameraweb.netlify.app/# has been updated as per the latest stable 3.3 and the latest versions of the plugins

      camera: ^0.10.1
      video_player: ^2.4.10
      camera_web: ^0.3.1

    Closing as fixed! in case anyone still encounters the issue, then please feel free to write in the comments and we will reopen it.

  18. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jan 5, 2023
  19. github-actions commented on Mar 4, 2023

    @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.

  20. locked as resolved and limited conversation to collaborators on Mar 4, 2023
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

    P2Important issues not at the top of the work listassigned for triageissue is assigned to a domain expert for further triagebrowser: chrome-androidonly manifests in Chrome on Androidbrowser: chrome-desktoponly manifests in desktop Chromefound in release: 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginp: video_playerThe Video Player pluginpackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions