I request permission from the user to operate the microphone, then I record the sound in wav format and send it to the API to store it.
When displayed on all devices, it works well
But I face a problem when playing wav format on iPhone
Is there any way to play wav file on iPhone?
I have tried many formats and libraries to play the file or convert the file to any format that works on the iPhone, such as mp3, a4m, acc, and more, and all of them are a failed attempt. It works on all devices except iPhones.
const startRecording = async () => {
setIsRecording(true);
setRecording(true);
setRecordedFile(null);
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorderRef.current = new MediaRecorder(stream);
mediaRecorderRef.current.ondataavailable = (event) => {
audioChunksRef.current.push(event.data);
};
mediaRecorderRef.current.onstop = () => {
const blob = new Blob(audioChunksRef.current, { type: "audio/wav" });
const file = new File([blob], "recording.wav", { type: "audio/wav" });
setRecordedFile({ file });
audioChunksRef.current = [];
if (onStop) {
onStop(file);
}
};
mediaRecorderRef.current.start();
};
I have tried many formats and libraries to play the file or convert the file to any format that works on the iPhone, such as mp3, a4m, acc, and more, and all of them are a failed attempt. It works on all devices except iPhones.