Skip to content

iOS - PlatformException when preparing player with recorded file #432

@0xRahad

Description

@0xRahad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions