使用本地文件作为< audio> SRC [英] Using local file as <audio> src

查看:149
本文介绍了使用本地文件作为< audio> SRC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用用户硬盘中的音频文件作为HTML5 < audio> src 属性$ c>标签?也许通过< input type =file/> ?这在生产中可能不是特别有用,但我仍然很好奇是否可以做到。

Is it possible to use an audio file from the user's hard drive as the src attribute for an HTML5 <audio> tag? Maybe through an <input type="file" />? This might not be particularly useful in production, but I'm still curious if it can be done.

推荐答案

我能想到的两种方式。

音频标记内:

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

或者您可以使用文件API使用Blob。

or you could use a Blob using the file API.

HTML:

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

JS:

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

这篇关于使用本地文件作为&lt; audio&gt; SRC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆