Is it possible to use data URIs in video and audio tags?

Viewed 25125

Assuming the following:

  1. The browser in question doesn't limit the size of data URIs.
  2. There is actually a purpose to doing this (so please refrain from asking "what's the point?" and "you do realize base64 encoding will expand your file by 33%, right?").

Is it technically possible to encode an entire video or audio file into base64, and embed it in an HTML document using either <audio> or <video>?

6 Answers

It should be possible, except in IE8 and below, which does not support Audio/Video elements. Note that Opera does limit the size of the URI.

That's probably because IE9 doesn't support WAV format in its audio element. Only MP3 is supported by now. I really hope that they change that in the RTM version.

As of 2022 I ran into file size limits with Firefox (v100.0) when using dataURI versions of podcast MP3s that were above about 30 minutes long or about 20MB.

Invalid URI. Load of media resource data:audio/mpeg;base64,...

Converting the FileReader result to binary and then a Blob as described here solved the issue.

Related