I have an application that loads an audio clip into an audio tag dynamically at runtime. It does this by converting the audio to a base64 data-url and assigning that to the tag's src attribute.
The issue is that the audio tag does not process the data until after the audio clip has been fully played through once. This issue shows up on the tag as (1) a lack of audio length, (2) a disabled time-scrubber and (3) the 3-dot icon not displaying. These features do appear as soon as the audio clip has been played for the first time.
I need a way to get the audio tag to process the audio clip as soon as it has been assigned. The user needs to be able to download the audio and fastforward with the time-scrubber without being forced to play through the entire audio clip.
I've searched extensively for a solution to this. I've tried audioTag.preload = "auto";
and calling audioTag.load();
after assigning the src. I've also let it sit for 15 minutes, in case it was just slow to load.
I am open to an alternative to using a base64 data-url formatting, if it will allow me to bypass this issue.
Thanks for any help you can provide.
EDIT: I see this issue in Chrome 80 and Firefox 75.
EDIT: I am generating an audio clip and assigning it to the audio tag in two ways: (1) from a 'file' input tag (2) from a MediaRecorder (connected to the web audio api).
Here is the 'file' input tag loading:
const reader = new FileReader();
reader.onload = () =>
{
const audioTag = document.getElementById("audioTag");
audioTag.preload = "auto";
audioTag.src = reader.result;
audioTag.load();
};
reader.readAsDataURL(fileInputTag.files[0]);
Here is the MediaRecorder loading:
mediaRecorder.onstop = () =>
{
const blob = new Blob(audioChunks, {type : "audio/wav"});
let reader = new FileReader();
reader.onload = () =>
{
let audioTag = document.getElementById("rec");
audioTag.preload = "auto";
audioTag.src = reader.result;
audioTag.load();
};
reader.readAsDataURL(blob);
};
I've just determined that opening a wav file created with audacity works fine. The issue only shows when opening an audio file saved from the MediaRecorder.
I've determined that MediaRecorder is actually producing 'webM/opus' files rather than 'wav' files. Research strongly suggests that 'webM' is the only recording option available for MediaRecorder on chrome (firefox also allows 'ogg'). No 'wav' file support. I'm going to post a "solution" now.
preload
works fine in normal workflow – Mhmdrz_A