0
votes

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?

1

1 Answers

1
votes

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 = ...

});