Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
878 stars 574 forks source link

[BUG]: Not work in flutter web #1057

Closed Ramtinmoradi closed 3 months ago

Ramtinmoradi commented 4 months ago

My project work with this packages on mobile and web, the web application for record sound is not work and has this error:

Error dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 296:3 throw packages/flutter_sound/public/flutter_sound_recorder.dart 675:7 _startRecorder dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 dart-sdk/lib/async/zone.dart 1661:54 runUnary dart-sdk/lib/async/future_impl.dart 163:18 handleValue dart-sdk/lib/async/future_impl.dart 847:44 handleValueCallback dart-sdk/lib/async/future_impl.dart 876:13 _propagateToListeners dart-sdk/lib/async/future_impl.dart 652:5 [_completeWithValue] dart-sdk/lib/async/future_impl.dart 722:7 callback dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7

package version is flutter_sound: ^9.7.2

Larpoux commented 4 months ago

You should check the parameters that you specify in startRecorder. It could be many things. Perhaps you specified a bad file name. Note: you don’t have access to a file system on web.

Ramtinmoradi commented 4 months ago

can you give me an example to use on the web?? It was working until a while ago.

Larpoux commented 4 months ago

This example

Terranic commented 4 months ago

observing a similar problem on Flutter web:

┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0   packages/flutter_sound/public/flutter_sound_recorder.dart 376:5     openRecorder
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 FS:<--- openAudioSession 
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
TypeError: dart.global.newRecorderInstance is not a function
packages/flutter_sound_web/flutter_sound_recorder_web.dart 171:18   openRecorder
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54  runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5  _async
packages/flutter_sound_web/flutter_sound_recorder_web.dart 161:28   openRecorder
packages/flutter_sound/public/flutter_sound_recorder.dart 402:51    _openAudioSession
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50  <fn>
dart-sdk/lib/async/zone.dart 1661:54                                runUnary
dart-sdk/lib/async/future_impl.dart 163:18                          handleValue
dart-sdk/lib/async/future_impl.dart 847:44                          handleValueCallback
dart-sdk/lib/async/future_impl.dart 876:13                          _propagateToListeners
dart-sdk/lib/async/future_impl.dart 652:5                           [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 722:7                           callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                    _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                     _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7  <fn>

which points to these lines:

  @override
  Future<void> openRecorder(
    FlutterSoundRecorderCallback callback, {
    required Level logLevel,
  }) async {
    int slotno = findSession(callback);
    if (slotno < _slots.length) {
      assert(_slots[slotno] == null);
      _slots[slotno] = newRecorderInstance(callback, callbackTable);
    } else {
      assert(slotno == _slots.length);
-->      _slots.add(newRecorderInstance(callback, callbackTable));
    }
    getWebSession(callback)!.initializeFlautoRecorder();
  }

this code using flutter_sound 9.7.2

class _AudioRecorderState extends State<AudioRecorder> {
  FlutterSoundRecorder? _recorder;
  bool _isRecording = false;
  late StreamController<FoodData> _streamController;

  @override
  void initState() {
    super.initState();
    _streamController = StreamController<FoodData>();

    asyncInit();
  }

  Future asyncInit() async {
    print("Init flutter sound recorder");
    _recorder = FlutterSoundRecorder();
    await _recorder!.openRecorder();
    print("Init flutter sound recorder done");
  }
....
Larpoux commented 4 months ago

I will look to that later. This problem is probably because your html file doesn’t load correctly flutter sound. But I would like to terminate startRecorder to stream on web, before looking to your issue.

Larpoux commented 4 months ago

Hi @Terranic . Can you tell me how do you build your Web app ? Android Studio ? VScode ? flutter build web ? Other ?

Terranic commented 4 months ago

Android Studio

Larpoux commented 4 months ago

It seems that you are not loading the js scripts :

Larpoux commented 4 months ago

and also :

Terranic commented 4 months ago

do I have to modify the index.html to include the scripts?

Larpoux commented 4 months ago

In old versions of flutter sound we had to include those scripts. But not anymore if you use the standard index.html provided by flutter. If you use your own index.html you have still to do that.

Larpoux commented 3 months ago

Please reopen this issue if you have still problems.