web-media-recorder
v1.0.6
Published
A versatile media recording library for audio and video with advanced features
Downloads
368
Maintainers
Readme
Web Media Recorder
A versatile, easy-to-use media recording library for JavaScript with support for both audio and video recording.
Features
- 🎙️ Record audio and video
- ⚙️ Highly configurable
- 🌐 Browser-compatible
- 📦 TypeScript support
- 🔬 Chunk-based recording
- 📝 Comprehensive callbacks
Installation
npm i web-media-recorder
Basic Usage
Audio Recording
import WebMediaRecorder from 'web-media-recorder';
async function recordAudio() {
const recorder = await WebMediaRecorder.create({
mediaType: 'audio',
onChunk: (chunkInfo) => {
console.log('Chunk recorded:', chunkInfo);
},
onStop: (recordingInfo) => {
// Handle final recording
const audioBlob = recordingInfo.blob;
}
});
recorder.start(); // Start recording
// Later...
recorder.stop(); // Stop recording
}
Video Recording
import WebMediaRecorder from 'web-media-recorder';
async function recordVideo() {
const recorder = await WebMediaRecorder.create({
mediaType: 'video',
constraints: {
video: { width: 1280, height: 720 },
audio: true
},
chunkDuration: 10, // 10-second chunks
onStop: (recordingInfo) => {
const videoBlob = recordingInfo.blob;
}
});
recorder.start();
}
API Reference
Options
mediaType
: 'audio' or 'video'chunkDuration
: Duration of each chunk (default: 5s)constraints
: Media stream constraintsmimeType
: Custom MIME typemaxDuration
: Maximum recording durationonChunk
: Callback for each chunkonStop
: Callback when recording stopsonError
: Error handling callback
License
MIT