I have wasted a ton of time implementing multiple audio recording options in a website I'm building but each one either only works in Chrome, only in Firefox, both but not Safari, and none work on iOS.
The website needs to allows the user to record their message and save it in a form state for submission.
All the current articles I am reading are a few months old and mention that iOS doesn't/will support it soon. I've tried mobile Chrome on iOS and it still didn't work.
Has anyone found a way to simply record audio in a browser as well as mobile website??
Things I've tried:
Currently using the following code which works, for Chrome and Firefox.
HTML
<audio controls src="" id="audio"></audio>
<a class="button" id="record">Record</a>
<input type="hidden" id="audiofile" name="audiofile" value="" aria-hidden="true"/>
Using the Francium Voice library:
Javascript
// Audio Recording for Phone Calls
$(document).on("click", "#record:not(.stop)", function(){
elem = $(this);
$("#audio").attr("src","");
$("#audiofile").val("");
Fr.voice.record($("#live").is(":checked"), function(){
elem.addClass("stop");
});
elem.html("Stop <label id='minutes'>00</label>:<label id='seconds'>00</label>");
var minutesLabel = document.getElementById("minutes");
var secondsLabel = document.getElementById("seconds");
var totalSeconds = 0;
setInterval(setTime, 1000);
function setTime() {
++totalSeconds;
secondsLabel.innerHTML = pad(totalSeconds % 60);
minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
}
function pad(val) {
var valString = val + "";
if (valString.length < 2) {
return "0" + valString;
} else {
return valString;
}
}
});
$(document).on("click", ".stop", function(){
elem = $(this);
elem.html("Record");
elem.removeClass("stop");
Fr.voice.export(function(base64){
$("#audio").attr("src", base64);
$("#audiofile").val(base64);
$("#audio")[0].play();
}, "base64");
Fr.voice.stop();
});
On your iPhone, go to “Settings” > “Control Center” > “Customize Controls”. Add “Screen Recording” to “INCLUDE” list. Go to Safari and hit on the page you want to record. Open “Control Center”, press the record button for a while, until it shows “Screen Recording” interface.
On the pop-up alert in the top of the window, click Allow to record an audio clip.
I found a technique that finally worked on Chrome, Firefox, and iOS Safari. There is an issue with getUserMedia in Safari though but I'm looking into that now.
https://github.com/GersonRosales/Record-Audios-and-Videos-with-getUserMedia
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With