简体   繁体   English

如何从静态文件夹中播放 html 格式的 mp3 文件?

[英]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.

相关问题 如何在Django应用程序上的静态Javascript上播放静态mp3文件? - How can I play a static mp3 file on static Javascript on a Django application? 如何在 Vue3 中播放 mp3 文件 - How to play mp3 file in Vue3 如何从 PPHP 播放 MP3 If Else - How to play MP3 from PPHP If Else 使用数据库中的文件路径从gridview的文件夹中播放音频(MP3)文件,但音频文件将位于网站目录之外 - Play audio (MP3) files from folder in gridview with filepath in database but the audio file will be outside to the website directory 如何从 mp3 文件中获取数据并自动将其放在 html 上? - how to get data from an mp3 file and put it on html automatically? 已修复尝试在 HTML 中暂停/播放 MP3 文件 - FIXED Trying to Pause/Play MP3 file in HTML 在 if 条件下播放 mp3 文件 - Play an mp3 file in a if condition 只有一个简单的html和js文件,我怎么能强制链接到MP3下载而不是只是播放? - with just a plain html and js file, how can i force a link to an mp3 to download instead of just play? 如何让 MP3 文件在 HTML/CSS/JS 页面的后台播放? - How to make MP3 file play in the background of HTML/CSS/JS page? 我想从列表中选择一个MP3并在html5中播放 - I want to select an mp3 from a list and play it in html5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM