flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.32k stars 27.53k forks source link

Super weird conflict bug with Flutter video_player and flutter_sound plugin on iOS #39550

Closed GraphicSound closed 4 years ago

GraphicSound commented 5 years ago

First of all, this bug only shows on iOS.

I'm writing a language learning app. So on one page, I'll play a short video first using Flutter video_player. Then I use flutter_sound to record the user's voice which allows them to practice speaking.

But most of the time, right after I start the recorder, the app will play the previous video's audio! Sometimes it's the whole audio being played and other times it's just a portion of it. And if I stop recording, the video's audio will be played again.

I've already made sure that the video player controller has been disposed. It looks like a cache or buffer issue?

BondarenkoStas commented 5 years ago

@GraphicSound can you please provide flutter doctor -v output, the phone specs, and if possible some example of the code or more detailed steps to be able to reproduce the issue?

GraphicSound commented 5 years ago

@BondarenkoStas

Render the video player:

_showVideo
                        ? new Align(
                            alignment: Alignment.topCenter,
                            child: Container(
                              color: themeDarkBackground,
                              child: AspectRatio(
                                aspectRatio:
                                    // _videoPlayerController.value.aspectRatio,
                                    widget.video['width'] /
                                        widget.video['height'],
                                child: new Stack(children: <Widget>[
                                  VideoPlayer(_videoPlayerController),
                                  _isVideoLoading
                                      ? Positioned.fill(
                                          child: Align(
                                              child: CircularProgressIndicator(
                                          valueColor:
                                              new AlwaysStoppedAnimation<Color>(
                                                  Colors.white),
                                        )))
                                      : Container()
                                ]),
                              ),
                            ))
                        : Container()

Start recording:

// Stop playing video
    if (_videoPlayerController != null) {
      log("hide video before recording");

      if (_showVideo) {
        _videoPlayerController.pause();

        setState(() {
          _showVideo = false;
        });
      }
    }

    setState(() {
      _isRecording = !_isRecording;
    });

    Directory appDocDir = await getApplicationDocumentsDirectory();
    String appDocPath = appDocDir.path;

    if (_isRecording) {
      _audioFilename = randomAlphaNumeric(11);
      log(_audioFilename);

      _flutterSound = new FlutterSound();

      //// By default this option is disabled, you can enable it by calling
      _flutterSound.setDbLevelEnabled(true);
      _flutterSound.setDbPeakLevelUpdate(0.3);

      // DISPOSE THE FREAKING VIDEO CONTROLLER
      if (_videoPlayerController != null) {
        log("DISPOSE THE FUCKING VIDEO CONTROLLER");
        _videoPlayerController.dispose();
      }

      _originalAudioPath =
          await _flutterSound.startRecorder(null, bitRate: 64000);
      print('audio path: $_originalAudioPath');

      _recorderSubscription = _flutterSound.onRecorderStateChanged.listen((e) {
        if (e != null) {
          _duration = e.currentPosition.toInt();
          // log(_duration.toString());
        }
      });

      _dbPeakSubscription =
          _flutterSound.onRecorderDbPeakChanged.listen((value) {
        // log(value.toString());
        if (value != null) {
          if (value.round() - _dbPeak > 10 || value.round() - _dbPeak < -10) {
            setState(() {
              // log(value.toString());
              _dbPeak = value;
            });
          }
        }
      });
    }
GraphicSound commented 5 years ago

flutter doctor -v

[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.6 18G87, locale en-US)
    • Flutter version 1.7.8+hotfix.4 at ...
    • Framework revision 20e59316b8 (6 weeks ago), 2019-07-18 20:04:33 -0700
    • Engine revision fee001c93f
    • Dart version 2.4.0

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at ...
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • CocoaPods version 1.7.1

[✓] iOS tools - develop for iOS devices
    • ios-deploy 1.9.4

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 38.2.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
GraphicSound commented 5 years ago

Both my iphone 6 and iphone xr encounter this bug.

TahaTesser commented 4 years ago

Hi @GraphicSound Are you still experiencing this issue? If so, can you please provide your flutter doctor -v and flutter run --verbose? Also, to better address the issue, would be helpful if you could post a minimal code sample to reproduce the problem Thank you

TahaTesser commented 4 years ago

Hi @GraphicSound Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away! Thanks for your contribution.

lock[bot] commented 4 years ago

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.