Reputation:
I want to use MediaRecorder
in order to record an existing mp3 file. I tried to pass an Audio
element as a source to MediaRecorder
, after calling captureStream() but it doesn't works.
new MediaRecorder(new Audio('./audio.mp3').captureStream(), {
audioBitsPerSecond: 16000
});
The error:
Uncaught DOMException: Failed to execute 'start' on 'MediaRecorder': The MediaRecorder cannot start becausethere are no audio or video tracks available.
How can I do that?
Upvotes: 0
Views: 1019
Reputation: 137171
You need to play()
that audio... (and wait it actually does), otherwise there is nothing in your stream to get recorded.
const aud = new Audio('./audio.mp3');
aud.play().then( () => {
const stream = aud.captureStream();
const recorder = new MediaRecorder(stream);
recorder.ondataavailable = ...
});
Upvotes: 1