llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
239 stars 202 forks source link

Permission condition is false in flutter web #430

Open Zeinab-Kouhkan opened 3 days ago

Zeinab-Kouhkan commented 3 days ago

Package version

Environment

Describe the bug

The browser microphone permission is set to 'Allowed' after displaying the permission notification, and it’s confirmed by the user. However, when starting the recording, the hasPermission check returns false. I tested this on HTTPS with both the CanvasKit and HTML renderers, and it still returns false.

Add your record configuration

Future<void> startRecorder() async {
    try {
      if (await _audioRecorder.hasPermission()) {

        const encoder = AudioEncoder.wav;

        if (!await _isEncoderSupported(encoder)) {

          return;
        }

        final devs = await _audioRecorder.listInputDevices();
        debugPrint('Devices Has Microphone:  ${devs.toString()}');

        const config = RecordConfig(encoder: encoder, numChannels: 1);

        // Record to file
        await _recordFile(config);

        // Record to stream
        // await recordStream(_audioRecorder, config);

        _recordDuration.value = 0;

        _startTimer();
      }
    } catch (e) {
      debugPrint(e.toString());
    }
  }

Run flutter doctor: Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Version 10.0.19045.5011], locale en-US) [√] Windows Version (Installed version of Windows is version 10 or higher) [!] Android toolchain - develop for Android devices (Android SDK version 34.0.0) X Android SDK file not found: D:\sdk\android\platforms\android-35\android.jar. [√] Chrome - develop for the web [X] Visual Studio - develop Windows apps X Visual Studio not installed; this is necessary to develop Windows apps. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2024.1) [√] VS Code (version 1.90.1) [√] Connected device (6 available) [√] Network resources

llfbandit commented 3 days ago

The description is unclear. hasPermission already prompts the user for permission. So how did you allow it?

Maybe a lead, hasPermission on web platform is not tied to a specific device. Did you rejected the permission before for another device?

Finally, hasPermission call can eventually be skipped on web platform, the permission prompt will be sent to the user if needed (so not rejected of course).

Zeinab-Kouhkan commented 2 days ago

This condition is checked when the user first starts the recording, and an access notification is displayed. The user grants access, but the condition returns false when the recording is restarted. According to your opinion on the web, should I ignore this condition?