audio_waveforms
audio_waveforms copied to clipboard
iOS - PlatformException when preparing player with recorded file
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 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
@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,
- Due to file corruption, audio player isn't able to load the file. Now, why this could be happening will have separate reasons.
- Path provided is actually correct?(Looks good to me from the code)