EncodingError when audio can be played #4098
Replies: 4 comments 4 replies
-
Most likely a MIME type issue. When you create an object URL with URL.createObjectURL(files[0]), the browser relies on the MIME type embedded in the File object. If the file lacks a recognizable or supported MIME type (e.g. from a raw recording or incorrectly tagged file), decoding can fail. You could try loading a blob directly instead. const audioBlob = files[0]
const waveSurfer = WaveSurfer.create({
container: $('#waveform')[0],
height: 30,
waveColor: '#B0578D',
progressColor: '#7d3d63',
cursorColor: '#000000',
blobMimeType: 'audio/mpeg', // pass the right MIME type here (optional)
})
waveSurfer.loadBlob(audioBlob) |
Beta Was this translation helpful? Give feedback.
-
I will set up a mini reproduction with a GitHub page later, please wait a second. |
Beta Was this translation helpful? Give feedback.
-
I use a large file (~40MB) in this demo (You should wait like 1 minute for the waveform to appear after press the play button): |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Bug description
I got the "EncodingError: Decoding failed" error when the audio element can be played back itself.
Please note that the audio.src is a video file, but the same code works on other platforms.
Environment
Minimal code snippet
The following code is written in Angular, but you can get the idea.
Expected result
Show the waveform after clicking the 'Interact' button.
Obtained result
Got the error
Screenshots
The screen just shows "EncodingError: Decoding failed", but I can play the audio by clicking the audio element's play button.
Beta Was this translation helpful? Give feedback.
All reactions