[英]How to play a mp3 file in html from a static folder?
I am trying to convert text to audio using python.I saved the converted audio file in static folder.I tried to play the audio file using the below html code.我正在尝试使用 python 将文本转换为音频。我将转换后的音频文件保存在静态文件夹中。我尝试使用以下 html 代码播放音频文件。
{%extends "main.html" %}
{% block file %}
<p>{{data}}</p>
<audio id="myAudio">
<source src="C:\Users\kousik\Desktop\static\uploads\welcome.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
<button onclick="playAudio()" type="button">Play Audio</button>
<script type="text/javascript">
var x = document.getElementById("myAudio");
function playAudio() {
x.play();
}
</script>
{% endblock %}
I am trying to play but i am getting error我正在尝试玩,但出现错误
Not allowed to load local resource: file:///C:/Users/kousik/Desktop/static/uploads/welcome.mp3
at first put you'r mp3 file into the project folder首先将您的 mp3 文件放入项目文件夹中
also try using it more flexible so everyone can access when it's on live server for example还尝试更灵活地使用它,以便每个人都可以在例如实时服务器上访问它
also change this "\\" to "/"也将此“\\”更改为“/”
ex:consider you'r file location is this例如:考虑您的文件位置是这样的
myproject->myfiles->welcome.mp3 myproject->myfiles->welcome.mp3
what you should do is你应该做的是
<source src="/myfiles/welcome.mp3"
type="audio/mpeg">
so when you put you'r project in any localhost,production it will work所以当你把你的项目放在任何本地主机上时,生产它就会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.