我想使用servlet将我的音频/视频文件流式传输到Web.
我尝试使用以下servlet:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
File file = new File("/Users/myfolder/Documents/workspace/love.mp3");
response.setContentType(getServletContext().getMimeType(file.getName()));
response.setContentLength((int) file.length());
Files.copy(file.toPath(), response.getOutputStream());
}
Run Code Online (Sandbox Code Playgroud)
以下HTML:
<a href="/media" data-format="mp3 ogg">Click Here!</a>
Run Code Online (Sandbox Code Playgroud)
但是,播放器正在加载... loading ... loading ...
这是怎么造成的,我该如何解决?