【问题标题】:Loading a new file into an audio element in HTML将新文件加载到 HTML 中的音频元素中
【发布时间】:2016-11-21 15:15:03
【问题描述】:

我一直在开发一个 web 应用程序,它允许用户标记和标记要播放的 mp3 的某些部分,作为该应用程序的一部分,我需要允许用户加载可以播放的新文件在浏览器中。我一直在尝试使用 HTML 中的文件和音频元素,但我可以找到一种方法使新选择的文件实际上成为音频元素的新来源。例如,我试过:

<audio id="song" controls>
  <source src="C:\Users\dalzinm\Downloads\Jaco.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

<input type="file" id="myFile" name="theFile"/>

<script>

var input = document.getElementById("myFile");
input.onclick = function ()
{
    this.value = null;
};

input.onchange = function ()
{
    var song = document.getElementById("song");
    song.pause();
    song.src=input.value;
    song.load();
    song.play();
};

</script>

但这似乎给了我一个错误,我现在确定我还能怎么做。任何帮助将不胜感激,谢谢!

【问题讨论】:

  • 你看到了什么错误?
  • 代码不起作用。 (我一直在用notepad++编辑,今天打算换用netbeans。)

标签: javascript html file audio mp3


【解决方案1】:

您不能只使用本地网址作为来源。相反,您可以使用 this article 中的 readURL 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    相关资源
    最近更新 更多