簡體   English   中英

HTML 音頻標簽在本地主機中無法使用 apache tomcat

[英]HTML audio tag not working in localhost with apache tomcat

So I am building a web app with Java, apache tomcat, Spring MVC, HTML... And I am trying to play mp3 file that is on external hard drive on my server machine. html 中的代碼如下所示:

<audio controls="">
    <source src="path/to/mp3/file" type="audio/mpeg">
</audio>

當我將 go 連接到我的互聯網並在本地主機中啟動此應用程序時,我在控制台中收到此錯誤:

HTTP 加載失敗,狀態為 404。加載媒體資源http://localhost:8080/path/to/mp3/file失敗。

我很確定這意味着該鏈接上沒有任何內容,但是如何播放與 HTML 文件不在同一文件夾中的音頻文件

It looks like you've simplified your question too much: I'm assuming that path/to/mp3/file refers to a URL that should start with file:/// , and is not a http:// URL - thus Tomcat不提供它,相反,瀏覽器很可能將其解釋為您服務器(本地主機)上的相對 URL。 這就是 404 的來源,因為它在其他地方。

沒有 Web 服務器(甚至 localhost)可以通過訪問文件系統來引用本地計算機上的任何內容。 通過 tomcat(帶有 http URL)提供您的音頻,您可以播放它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM