audio_waveforms icon indicating copy to clipboard operation
audio_waveforms copied to clipboard

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

Open AmalBenny1 opened this issue 2 years ago • 15 comments

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)

  • Device: [iPhone6s]
  • OS: [iOS12.5.7]
  • Flutter SDK3.7.11
  • Dart SDK2.19.6

AmalBenny1 avatar May 08 '23 11:05 AmalBenny1

yeah I also face this issue ...

tanzeemhussain avatar May 10 '23 15:05 tanzeemhussain

any update ?

tanzeemhussain avatar May 10 '23 22:05 tanzeemhussain

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

AmalBenny1 avatar May 22 '23 10:05 AmalBenny1

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.

Theunodb avatar May 23 '23 13:05 Theunodb

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

rahulrmishra avatar Jul 18 '23 13:07 rahulrmishra

anyone solve it?

AliSamir070 avatar Jul 23 '23 14:07 AliSamir070

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.

ujas-m-simformsolutions avatar Aug 13 '23 13:08 ujas-m-simformsolutions

Having the same issue here.

TNelen avatar Aug 17 '23 18:08 TNelen

Having the same issue here.

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

Ujas-Majithiya avatar Aug 17 '23 18:08 Ujas-Majithiya

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;
  }
}```

TNelen avatar Aug 17 '23 19:08 TNelen

@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

ujas-m-simformsolutions avatar Aug 17 '23 19:08 ujas-m-simformsolutions

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

TNelen avatar Aug 18 '23 08:08 TNelen

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

MazEbeid avatar Nov 28 '23 20:11 MazEbeid

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!.

OmarBakry-eg avatar Jan 25 '24 11:01 OmarBakry-eg