mediaplayer java_Java平台下的Media Player

实验四 windows或java平台下的Media Player(6学时)基本要求l 实现media player,支持多种媒体类型的播放l 视频:avil 音频:wav、midil 图象序列:图象浏览,幻灯l 播放列表功能l Generic listl 自定义的复杂播放Bonus界面美观-skin,可更换?更丰富的媒体类型:MP3,WMA,MPEG4,JPEG,PNG,WMF,F...
摘要由CSDN通过智能技术生成

实验四  windows或java平台下的Media Player(6学时)

基本要求

l  实现media player,支持多种媒体类型的播放

l  视频:avi

l  音频:wav、midi

l  图象序列:图象浏览,幻灯

l  播放列表功能

l  Generic list

l  自定义的复杂播放

Bonus

界面美观-skin,可更换?

更丰富的媒体类型:

MP3,WMA,MPEG4,JPEG,PNG,WMF,Flash……

这些附加媒体类型的播放可以使用控件

这个实验参考了网上的一些相关资料,https://github.com/Al-assad

在实现这个实验的时候用到了JavaFX,需要现在eclipse中安装JavaFX插件。安装完成之后,新建一个JavaFX Project。

最后的视频播放效果如下所示,这是从网易云音乐下载的周杰伦的《七里香》MV,效果还不错,可以调节音量和进度。

音频播放效果如下所示

主要代码如下所示

package application;

public class Log {

public static void i(String tag, String content) {

System.out.println("[INFO][" + tag + "]: " + content);

}

public static void e(String tag, String content) {

System.out.println("[ERROR][" + tag + "]: " + content);

}

}

package application;

import javafx.application.Application;

import javafx.scene.*;

import javafx.event.*;

import javafx.geometry.*;

import javafx.scene.control.*;

import javafx.scene.layout.*;

import javafx.scene.paint.*;

import javafx.stage.*;

import player.*;

import java.io.*;

import java.net.*;

public class Main extends Application {

MyMediaPlayer player;

FileChooser fileChooser;

MenuBar menuBar;

BorderPane pane;

Group root;

public static final String[] IMAGE_POSTFIX = {

"bmp", "dib",

"png",

"jpeg", "jpg"

};

public static final String[] AUDIO_POSTFIX = {

"mp3",

"wav"

};

public static final String[] VIDEO_POSTFIX = {

"avi",

"mp4"

};

public static final String FILENAME = "69_output_2.mp4";

public static String getPostfix(File file) {

String filename = file.getName();

String ret;

if (filename == null || filename.length() == 0) {

ret = null;

} else {

char[] curName = filename.toCharArray();

int indexDot = -1;

for (int i = curName.length - 1; i >= 0; i--) {

if (curName[i] == '.') {

indexDot = i;

break;

}

}

if (indexDot == -1) {

ret = null;

} else {

ret = filename.substring(indexDot + 1);

}

}

return ret;

}

public static boolean isThisType(String postfix, String[] postfixList) {

for (String item: postfixList) {

if (postfix.compareToIgnoreCase(item) == 0) {

return true;

}

}

return false;

}

public class UnknownFileTypeException extends Exception {

public UnknownFileTypeException() {

super("Cannot determine the file type. ");

}

public UnknownFileTypeException(String message) {

super(message);

}

}

@Override

public void start(Stage primaryStage) throws Exception{

//添加菜单栏,用于打开文件

MenuItem open = new MenuItem("Open");

Menu menuFile = new Menu("File");

menuBar = new MenuBar();

menuFile.getItems().add(open);

menuBar.getMenus().add(menuFile);

fileChooser = new FileChooser();

open.setOnAction(new EventHandler(){

public void handle(ActionEvent e){

File file = fileChooser.showOpenDialog(primaryStage);

if (file != null){

try {

Log.i("File", file.toURI().toURL().toExternalForm());

String postfix = getPostfix(file);

if (postfix == null) {

throw new UnknownFileTypeException();

}

if (isThisType(postfix, IMAGE_POSTFIX)) {

//测试嵌入式调用

MyMediaPlayer.popup(file.toURI().toURL().toExternalForm());

} else if (isThisType(postfix, AUDIO_POSTFIX)) {

//测试嵌入式调用

MyMediaPlayer.popup(file.toURI().toURL().toExternalForm());

} else if (isThisType(postfix, VIDEO_POSTFIX)) {

/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值