Canardoux / flutter_sound

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

[BUG]: Not work in flutter web #1057

Closed Ramtinmoradi closed 2 weeks ago

Ramtinmoradi commented 1 month 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 1 month 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 1 month ago

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

Larpoux commented 1 month ago

This example

Terranic commented 1 month 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 1 month 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 1 month ago

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

Terranic commented 1 month ago

Android Studio

Larpoux commented 1 month ago

It seems that you are not loading the js scripts :

Larpoux commented 1 month ago

and also :

Terranic commented 1 month ago

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

Larpoux commented 1 month 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 2 weeks ago

Please reopen this issue if you have still problems.