Using local file as <audio> src

Can I use an audio file from a user's hard drive as an attribute srcfor an HTML5 tag <audio>? Maybe through <input type="file" />? This may not be particularly useful in production, but I'm still wondering if this can be done.

+4
source share
1 answer

I can think of two ways.

In the audio tag :

src="file:///C:/.../file.mp3"

or you can use Blob using the API files.

HTML:

<input type="file"></input>

JS:

audio.src = URL.createObjectURL(document.getElementsByTagName('input')[0].files[0]);
+9
source

Source: https://habr.com/ru/post/1526604/


All Articles