#ac-recorder
Based on MediaRecorder and AudioContext implementation: can record audio and canvas on a web page simultaneously, and generate a video file to download locally.
🔗 Chrome support 🔗 Support Safari
To see it in action, run
npm install
npm run build
npm start
and hit "start recording", then "preview video".
Instantiation parameters: constructor(targetAudio, targetCanvas)
- targetAudio: the audio element that can play audio or a '#id_name' or '.class_name' css selector
- targetCanvas: The canvas element that plays the animation or video or a '#id_name' or '.class_name' css selector
.setOptions()
.createRecorder()
.start()
.pause()
.resume()
.stop()
.preview()
.closePreview()
.download()
.changeAudio()
- Import the ACRecorder class:
import { ACRecorder } from "./index.js";
- Instantiate ACRecorder, and pass in the audio element and canvas element to be recorded:
let ACR = new ACRecorder(document. querySelector("#audio"), "#canvas");
- Set up listening events (optional):
ACR.setListeners({
start: () => {...},
fail: () => {...},
pause: () => {...},
resume: () => {...},
stop: () => {...}
});
- Start recording:
ACR.start();
- Pause recording:
ACR. pause();
- Resume recording:
ACR. resume();
- Stop recording:
ACR. stop();
- Preview recorded video (optional):
ACR. preview();
- Turn off video preview (optional):
ACR. closePreview();
- Download recorded video (optional):
ACR.download();
- Destroy the recorder (optional):
ACR.destroy();
new AudioContext()
must be executed after a user operation, otherwise the warning "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page" will appear, causing the audio to fail to play .