audio_waveforms icon indicating copy to clipboard operation
audio_waveforms copied to clipboard

iOS - PlatformException when preparing player with recorded file

Open 0xRahad opened this issue 6 months ago • 2 comments

When trying to play a voice recording saved via RecorderController, I encounter the following exception on iOS:

PlatformException(AudioWaveforms, Failed to prepare player, The operation couldn’t be completed. (OSStatus error 1685348671.), null)

  void getDir() async {
    final path =
        '${(await getTemporaryDirectory()).path}/voice_${DateTime.now().millisecondsSinceEpoch}.m4a';
    recordedFilePath = path;
    setState(() {});
  }

  Future<void> startRecord() async {
    if (recorderController.hasPermission) {
      await recorderController.record(
        androidEncoder: AndroidEncoder.aac,
        androidOutputFormat: AndroidOutputFormat.mpeg4,
        iosEncoder: IosEncoder.kAudioFormatMPEG4AAC,
        bitRate: 128000,
        sampleRate: 44100,
        path: recordedFilePath,
      );
      recorderController.updateFrequency = const Duration(milliseconds: 100);
      recorderController.overrideAudioSession = false;
      isRecording.value = true;
    }
  }

  Future<void> stopRecord() async {
    if (recorderController.isRecording) {
      recorderController.reset();
      recordedFilePath = await recorderController.stop();
      if (recordedFilePath != null) {
        print(recordedFilePath);
        chatController.sendMessage(
          ChatMessage(
            id: DateTime.now().toString(),
            content: recordedFilePath ?? "",
            type: MessageType.voice,
            timestamp: DateTime.now(),
            isMe: true,
            avatarUrl:
                "https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250",
          ),
        );
        isRecording.value = false;
        isRecordingCompleted.value = true;
      }
    }
  }

0xRahad avatar May 29 '25 15:05 0xRahad

@0xRahad did you find any solution to this? I'm having the same problem using flutter 3.32.1, physical ios device and audio_waveforms 1.3.0

novas1r1 avatar Jun 06 '25 07:06 novas1r1

@0xRahad and @novas1r1 can you please confirm first if recorded audio file isn't corrupted? There two possibility I see here which might causing this issue,

  1. Due to file corruption, audio player isn't able to load the file. Now, why this could be happening will have separate reasons.
  2. Path provided is actually correct?(Looks good to me from the code)

ujas-m-simformsolutions avatar Jul 20 '25 17:07 ujas-m-simformsolutions