2013-03-08 42 views
0

我想播放音頻文件,它在我有.html文件時有效,但是當我在.jsp文件中運行相同的代碼時,文件無法播放。我正在使用Netbeans IDE。有人可能會指出錯誤,下面是jsp代碼。使用HTML 5和jsp播放音頻文件

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
</head> 
<body> 
    <h1>Hello World!</h1> 
    <audio controls> 

     <source src="C:\Users\Desktop\1.mp3" type="audio/mpeg"> 

    </audio> 

</body> 

回答

1

src屬性不應該是音頻文件的文件位置。相反,它應該是該文件的URL。所以你的情況,儘量

<audio controls> 
    <source src="http://localhost:8080/PathToMp3/1.mp3" type="audio/mpeg"> 
</audio> 

其中http://localhost:8080/PathToMp3/1.mp3是你的MP3文件的URL。

+0

仍然沒有工作! – rishabh 2013-03-08 13:33:38

+1

@rishabh在這裏很好用:http://jsfiddle.net/sDCqj/ – Lipis 2013-03-08 13:50:00

+0

@ Lipis + 1 for metallica – deadlock 2013-03-08 13:56:29

0
<audio controls> 
    <source src="http://localhost:8080/PathToMp3/1.mp3" type="audio/mpeg"> 
</audio> 

,如果它不能正常工作使用此

<embed src="">