SimformSolutionsPvtLtd / audio_waveforms

Use this plugin to generate waveforms while recording audio in any file formats supported by given encoders or from audio files. We can use gestures to scroll through the waveforms or seek to any position while playing audio and also style waveforms
https://pub.dev/packages/audio_waveforms
MIT License
275 stars 141 forks source link

PlatformException(AudioWaveforms, Failed to start recording, null, null) #214

Open AmalBenny1 opened 1 year ago

AmalBenny1 commented 1 year ago

PlatformException(AudioWaveforms, Failed to start recording, null, null), just this error and the audio is not recorded and the audio waves are not shown(Working fine on android devices but issue is with IOS)

tanzeemhussain commented 1 year ago

yeah I also face this issue ...

tanzeemhussain commented 1 year ago

any update ?

AmalBenny1 commented 1 year ago

https://stackoverflow.com/questions/70019765/flutter-flutter-webview-plugin-error-nsnull-length-unrecognized-selector-sent

please refer this link, it is an issue with the permissions given in the info.plist

Theunodb commented 1 year ago

https://stackoverflow.com/questions/70019765/flutter-flutter-webview-plugin-error-nsnull-length-unrecognized-selector-sent

please refer this link, it is an issue with the permissions given in the info.plist

This did not work for me, still looking for a workaround.

rahulrmishra commented 1 year ago

The issue only occurs in iOS physical devices. It works fine in the iOS simulator. Any update?

AliSamir070 commented 1 year ago

anyone solve it?

ujas-m-simformsolutions commented 1 year ago

Can anyone please confirm that in the below scenarios an error happens?

  1. The microphone is used by another app before recording using this plugin.
  2. The path parameter is not provided in the record function.
  3. A path is provided in the record function, but it is in a sub-directory.

If an error isn't happening in the above-mentioned scenario, then please share the reproducible code from the example.

TNelen commented 1 year ago

Having the same issue here.

Ujas-Majithiya commented 1 year ago

Having the same issue here.

Can you please share your implementation so that we find the root cause of it.

TNelen commented 1 year ago

This is my audioService. the startRecording function throws the error.


import 'package:path_provider/path_provider.dart';

class AudioService {
  String? path;
  String? musicFile;
  bool isRecording = false;
  late Directory appDirectory;
  final recorderController = RecorderController()

  Future<String?> stopRecording() async {
    String? path = await recorderController.stop(false);

    return path;
  }

  void resetRecording() {
    recorderController.reset();
  }

  void startRecording() async {
    if (!isRecording) {
      final String fileName = locator<TrackRepository>().selectedTrack!.name + '${DateTime.now().millisecondsSinceEpoch}';
      Directory? directory;
      directory = await getApplicationDocumentsDirectory();
      final filepath = '${directory.path}/' + fileName + ".mp3";
      await recorderController.record(path: filepath);
    }
  }

  bool getIsRecording() {
    return recorderController.isRecording;
  }
}```
ujas-m-simformsolutions commented 1 year ago

@TNelen Thank you for the code and the issue here is that you are trying to record audio in mp3 format which is not supported by IOS's AVAudioRecorder, So I would suggest to record in some other format which supported by native recorder & selected encoder. i.e m4a

TNelen commented 1 year ago

@ujas-m-simformsolutions ah thx! Changing it to mpeg4 fixed the issue.

MazEbeid commented 9 months ago

So what settings do I need to have in order to be able to record and share audio between Android and iOS?

OmarBakry-eg commented 7 months ago

The issue only occurs in iOS physical devices. It works fine in the iOS simulator. Any update?

For me the issue ain't work in iOS simulator too, is there any solution atm?.

Here's my interface implementation :

import 'package:audio_waveforms/audio_waveforms.dart';

interface class AudioController {
  final RecorderController controller = RecorderController()
    ..androidEncoder = AndroidEncoder.aac
    ..androidOutputFormat = AndroidOutputFormat.mpeg4
    ..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC;

  Future<bool> get checkAudioRecordingPermission async =>
      await controller.checkPermission();

  bool get isRecording => controller.isRecording;

  Future<void> startRecording({String? path}) async {
    await controller.record(path: path); // Record (path is optional)
  }

  void pauseRecording() async {
    await controller.pause();
  }

  Future<String?> stopRecording({bool callReset = true}) async {
    return await controller.stop(callReset);
  }

  void refreshRecording({bool useShouldRefresh = false}) {
    if (useShouldRefresh) {
      if (controller.shouldRefresh) {
        controller.refresh();
      }
    } else {
      controller.refresh();
    }
  }

  void disposeRecorder() async {
    controller.dispose();
  }

  void reset() {
    controller.reset();
  }
}

And here's the issue that I face :

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(AudioWaveforms, Failed to prepare player, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:322:18)
<asynchronous suspension>
#2      AudioWaveformsInterface.preparePlayer (package:audio_waveforms/src/base/audio_waveforms_interface.dart:100:18)
<asynchronous suspension>
#3      PlayerController.preparePlayer (package:audio_waveforms/src/controllers/player_controller.dart:122:24)
<asynchronous suspension>
#4      _VoiceMessageViewState.initState.<anonymous closure> (package:wud_patient/src/utils/chatview_package/lib/src/widgets/voice_message_view.dart:77:22)
<asynchronous suspension>

Appreciate your help!.

RothaSoeurn commented 3 months ago

ok. bro

OmarBakry-eg commented 1 month ago

No updates for now, but I managed to download the file and prepare it from a local path and it works fine.

But is there any way to prepare or play a record from network?

Thanks