【发布时间】:2013-11-08 15:54:26
【问题描述】:
我有一个像这样的嵌入标签
<embed id="player" style="height:100%;width:100%"src="../PlayAudio2" controller="true" autoplay="true" autostart="True" type="audio/wav" />
我可以从 servlet doGet 播放文件
File file = new File("Z:/53611.wav");
FileInputStream fis;
byte[] buffer=null;
try {
fis = new FileInputStream(file);
buffer= new byte[fis.available()];
fis.read(buffer);
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
response.setContentType("audio/vnd.wave");
try {
response.getOutputStream().write(buffer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
春天有没有办法我试过了
<embed id="player" style="height:100%;width:100%"src="PlayAudio.html" controller="true" autoplay="true" autostart="True" type="audio/wav" />
请求处理程序代码与 servlet 中相同,但这里甚至没有收到对 PlayAudio.html 的请求。我在 Spring 中该怎么做。
编辑: 控制器
@Controller
@RequestMapping("main")
public class ApplicationController {
@RequestMapping(value="Login.html",method=RequestMethod.POST)
public String showhome(){
return "home";
}
@RequestMapping(value="PlayFile.html",method=RequestMethod.GET)
public void playAudio(HttpServletRequest request,HttpServletResponse response){
System.out.println("--playFile");
File file = new File("Z:/53611.wav");
FileInputStream fis;
byte[] buffer=null;
try {
fis = new FileInputStream(file);
buffer= new byte[fis.available()];
fis.read(buffer);
fis.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setContentType("audio/vnd.wave");
try{
response.getOutputStream().write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
}
}
我在 webcontent 下的主文件夹中有 Home.jsp,其中有
<embed id="player" style="height:100%;width:100%" src="PlayFile.html" controller="true" autoplay="true" autostart="True" type="audio/wav" />
和url映射
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
但它不工作(没有收到PlayFile.html处理程序的请求)
【问题讨论】:
-
PlayAudio.html是如何生成的?我在您的代码中没有看到任何映射到此 URL 的内容。
标签: java spring servlets spring-mvc audio-streaming