多音频自动连续播放,且标识正在播放的文件
一、前端界面显示多选框和播放按钮
勾选多选框选择播放的音频文件,点击播放,跳转到播放界面
function PlayAll(){
var hdIdValue = $("#hdIdValue").val();
if(hdIdValue=="")
alert("请选择数据!");
else{
$.ajax({
type : "POST",
url : "recordsCopy.do?recordpath="+window.encodeURI(hdIdValue),
success : function() {
layer.open({
type: 2,
title: '语音播放',
move: false,
area: ['750px', '500px'],
content: "recordsplay?hdIdValue="+hdIdValue,
end: function () {
location.reload();}
})
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
}
二、recordsCopy.do复制音频文件到服务器指定位置,以便播放
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String recordpathss=req.getParameter("recordpath");
String[] recordpaths=recordpathss.split(",");
String realPath = req.getSession().getServletContext().getRealPath("/");
doFolder(realPath+"temprecord");
for(int i=0;i<recordpaths.length;i++) {
String recordpath=recordpaths[i];
if(recordpath != null) {
String filename = recordpaths[i].split("/")[recordpaths[i].split("/").length-1];
File source = new File(recordpath);
File dest = new File(realPath+"temprecord/"+filename);
// copy file using FileStreamslong start = System.nanoTime();
copyFileUsingFileStreams(source, dest);
}
}
}
private static void copyFileUsingFileStreams(File source, File dest)
throws IOException {
InputStream input = null;
OutputStream output = null