Skip to content

Commit

Permalink
safari only supports mp4 audio. Downloading seems to be fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
krismakesstuff committed Apr 29, 2024
1 parent 756ec36 commit 5122a2b
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions rnbo-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ let date = Date.now();
console.log("Date now: " + date);
let recordedBlob = [];

var isSafari = window.safari !== undefined;
if (isSafari){
console.log("Safari, yeah!");
} else {
console.log("Not Safari");
}


export async function createRNBODevice(patchExportURL) {


Expand Down Expand Up @@ -70,18 +78,32 @@ export async function createRNBODevice(patchExportURL) {

// connect gain node to recorder
let streamDestination = context.createMediaStreamDestination();
let options = {
mimeType: 'audio/webm;codecs=pcm',


let options;

if (isSafari) {
options = {
mimeType: "audio/mp4",
};
} else {
options = {
mimeType: 'audio/webm;codecs=pcm',
};
}
mediaRecorder = new MediaRecorder(streamDestination.stream, options);

// let options = {
// mimeType: 'audio/webm;codecs=pcm',
// }

const types = [
"audio/webm",
"audio/webm;codecs=pcm",
"audio/webm;codecs=opus",
"audio/mpeg",
"audio/wav",
"audio/aac",
"audio/mp4",
];

for (const type of types) {
Expand All @@ -91,6 +113,10 @@ export async function createRNBODevice(patchExportURL) {
}`,
);
}

mediaRecorder = new MediaRecorder(streamDestination.stream, options);




// Media Recorder Event onstart
Expand All @@ -112,6 +138,17 @@ export async function createRNBODevice(patchExportURL) {
console.log("recording stopped");
console.log(recordedBlob);

if (mediaRecorder.mimeType == "audio/mp4"){
let mp4Blob = new Blob(recordedBlob, {type: "audio/mp4"});
let url = URL.createObjectURL(mp4Blob);

let downloadLink = document.getElementById("download-link");
let fileName = "shift-recording-" + (Date.now() - date);

downloadLink.href = url;
downloadLink.download = fileName;
downloadLink.click();
}

const reader = new FileReader();
//let arrayBuffer;
Expand Down Expand Up @@ -141,7 +178,7 @@ export async function createRNBODevice(patchExportURL) {
}

// reads blob as an ArrayBuffer
reader.readAsArrayBuffer(recordedBlob[0]);
//reader.readAsArrayBuffer(recordedBlob[0]);


}
Expand Down

0 comments on commit 5122a2b

Please sign in to comment.