import java.io.File;
import java.io.FileOutputStream;
import java.util.Collection;
import java.util.Scanner;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ResourceHandler;
public abstract class KAPlayerUtils {
public static final String BASE_DIR = System.getProperty("user.dir");
protected static final class WebServer {
public static final WebServer DEFAULT_WEB_SERVER = new WebServer(8121, "/web");
private Server webServer;
public WebServer(int port, String webDirectory) {
// initialize web server
webServer = new Server(port);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(BASE_DIR + webDirectory);
webServer.setHandler(resourceHandler);
}
public void start(int port) throws Exception {
if (webServer.isStopped()) {
webServer.start();
}
}
public void stop() throws Exception {
webServer.stop();
webServer.destroy();
}
}
public static void export(File directory, String playlistXml) throws Exception {
// list all audio files
Collection<File> audioFiles = FileUtils.listFiles(directory, new String[] {
"asf", "mpeg-1", "mpeg-2", "wav", "avi", "midi", "vod", "au", "mp3"
}, true);
// create audio document
Element rootElem = DocumentHelper.createElement("playlist");
Document audioDoc = DocumentHelper.createDocument(rootElem);
if (audioFiles != null && !audioFiles.isEmpty()) {
// sort files by modified
audioFiles = audioFiles.stream().sorted((File audioFile1, File audioFile2) ->
Long.compare(audioFile2.lastModified(), audioFile1.lastModified())
).collect(Collectors.toList());
// add audio Elements
for (File audioFile : audioFiles) {
String audioName = FilenameUtils.getBaseName(audioFile.getName());
String audioUrl = "file:///" + FilenameUtils.separatorsToUnix(audioFile.getPath());
Element musicElem = rootElem.addElement("music");
musicElem.addElement("name").setText(audioName);
musicElem.addElement("url").setText(audioUrl);
}
}
// format and output audio document
OutputFormat xmlFormat = OutputFormat.createPrettyPrint();
xmlFormat.setIndent(" ");
xmlFormat.setNewLineAfterDeclaration(false);
XMLWriter xmlWriter = null;
try {
xmlWriter = new XMLWriter(new FileOutputStream(new File(BASE_DIR, playlistXml)), xmlFormat);
xmlWriter.write(audioDoc);
} finally {
if (xmlWriter != null) {
xmlWriter.close();
}
}
}
public static void main(String[] args) {
System.out.println(">>>>>> START >>>>>>");
try (Scanner scanner = new Scanner(System.in)) {
// export audio playlist
System.out.print("Do you want to export audio files? (yes/enter others to continue): ");
if ("yes".equals(scanner.nextLine())) {
System.out.print("Audio files directory: ");
KAPlayerUtils.export(new File(scanner.nextLine()), "/web/xml/playlist.xml");
}
// start web server
KAPlayerUtils.WebServer webServer = KAPlayerUtils.WebServer.DEFAULT_WEB_SERVER;
webServer.start(8121);
System.out.println("Web server url is 'http://localhost:8121/', you can stop the web server by entering 'yes'.");
while (true) {
if ("yes".equals(scanner.nextLine())) {
break;
}
}
webServer.stop();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("<<<<<< END <<<<<<");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于WindowsMediaPlayer网页播放器的设计与实现源码
共29个文件
png:10个
jar:8个
js:3个
需积分: 18 14 下载量 131 浏览量
2017-03-19
11:52:27
上传
评论
收藏 1.55MB ZIP 举报
温馨提示
这是【基于WindowsMediaPlayer网页播放器的设计与实现】博客的源码,更多说明请见博客:http://blog.csdn.net/kingwtd/article/details/53969333。
资源推荐
资源详情
资源评论
收起资源包目录
kaplayer.zip (29个子文件)
kaplayer
bin
LICENSE 10KB
start.bat 368B
java
KAPlayerUtils.java 4KB
web
js
kaplayer.js 15KB
kaslider.js 4KB
xml
recommend.xml 4KB
playlist.xml 434B
css
kaplayer.css 8KB
imgs
tab.png 3KB
bgound.png 9KB
volume.png 3KB
mode.png 3KB
route.png 3KB
stop.png 5KB
ball.png 3KB
previous-next.png 9KB
action.png 3KB
play-pause.png 9KB
favicon.ico 4KB
index.html 3KB
lib
jquery-1.9.1.js 262KB
lib
dom4j-1.6.1.jar 307KB
jetty-util-8.1.21.v20160908.jar 281KB
commons-io-2.5.jar 204KB
jetty-server-8.1.21.v20160908.jar 352KB
jetty-continuation-8.1.21.v20160908.jar 21KB
jetty-http-8.1.21.v20160908.jar 94KB
jetty-io-8.1.21.v20160908.jar 104KB
servlet-api-3.0.jar 196KB
共 29 条
- 1
资源评论
KingWTD
- 粉丝: 28
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功