不全~代碼發(fā)不了了~,剩下的是播放器的關(guān)閉以及播放格式的支持與否,不麻煩的自己寫吧
公司主營(yíng)業(yè)務(wù):成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)建站是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)建站推出開(kāi)原免費(fèi)做網(wǎng)站回饋大家。
MediaPlayer.java
----------------------------------------------------------------------------
//程序主文件
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.*;
import java.io.*;
import java.util.*;//為了導(dǎo)入Vector
//import com.sun.java.swing.plaf.windows.*;
public class MediaPlayer extends JFrame implements ActionListener,Runnable
{
private JMenuBar bar;//菜單條
private JMenu fileMenu,choiceMenu,aboutMenu;
private JMenuItem openItem,openDirItem,closeItem,about,infor;
private JCheckBoxMenuItem onTop;
private boolean top=false,loop;//設(shè)定窗口是否在最前面
private Player player;//Play是個(gè)實(shí)現(xiàn)Controller的接口
private File file,listFile;//利用File類結(jié)合JFileChooser進(jìn)行文件打開(kāi)操作,后則與list.ini有關(guān)
private Container c;
//private UIManager.LookAndFeelInfo[] look;
private String title,listIniAddress;//標(biāo)題
private FileDialog fd;
private JPanel panel,panelSouth;
private Icon icon; //開(kāi)始進(jìn)入的時(shí)候要顯示的圖標(biāo),它為抽象類,不能自己創(chuàng)建
private JLabel label,listB;//用來(lái)顯示圖標(biāo)
private JList list;//播放清單
private JScrollPane scroll;//使播放清單具有滾動(dòng)功能
private ListValues listWriteFile;//用于向文件中讀取對(duì)象
private ObjectInputStream input;//對(duì)象輸入流
private ObjectOutputStream output;//對(duì)象輸出流
private JPopupMenu popupMenu;//鼠標(biāo)右鍵彈出菜單
private JMenuItem del,delAll,reName; //彈出菜單顯示的菜單項(xiàng),包括刪除,全部刪除和重命名
private Vector fileName,dirName,numList;
private String files,dir;
private int index;//曲目指針
private Properties prop;//獲得系統(tǒng)屬性
private int indexForDel;//標(biāo)志要?jiǎng)h除的列表項(xiàng)目的索引
private ButtonGroup buttonGroup;//控制按鈕組
private JRadioButtonMenuItem[] buttonValues;
private String[] content={"隨機(jī)播放","順序播放","單曲循環(huán)"};
private DialogDemo dialog1;
//private JDialogTest dialog2;//用于顯示播放清單
MediaPlayer()//構(gòu)造函數(shù)
{
super("java音頻播放器1.1版");//窗口標(biāo)題
c=getContentPane();
c.setLayout(new BorderLayout());
//c.setBackground(new Color(40,40,95));
fileName=new Vector(1);
dirName=new Vector(1);
numList=new Vector(1);//構(gòu)造三個(gè)容器用于支持播放清單
//vectorToString=new String[];
//prop=new Properties(System.getProperties());
//listIniAddress=prop.getProperty("user.dir")+"\\list.ini";
//listFile=new File(listIniAddress);//本來(lái)這些代碼用來(lái)取的系統(tǒng)屬性,后來(lái)
//發(fā)現(xiàn)根本就不用這么麻煩
listFile=new File("list.ini");//直接存于此目錄
Thread readToList=new Thread(this);//注意編線程程序的時(shí)候要注意運(yùn)行的時(shí)候含有的變量?jī)|定義或者初始化,
//這就要求線程要等上述所說(shuō)的情況下再運(yùn)行,否則很容易發(fā)生錯(cuò)誤或則異常
list=new JList();
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list.setSelectionForeground(new Color(0,150,150));
list.setVisibleRowCount(10);
list.setFixedCellHeight(12);
list.setFixedCellWidth(250);
list.setFont(new Font("Serif",Font.PLAIN,12));
list.setBackground(new Color(40,40,95));
list.setForeground(new Color(0,128,255));
//list.setOpaque(false);
list.setToolTipText("點(diǎn)右鍵顯示更多功能");//創(chuàng)建播放清單并設(shè)置各個(gè)屬性
list.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2) //判斷是否雙擊
{
index = list.locationToIndex(e.getPoint());//將鼠標(biāo)坐標(biāo)轉(zhuǎn)化成list中的選項(xiàng)指針
createPlayer2();
//System.out.println("Double clicked on Item " + index);,此是測(cè)試的時(shí)候加的
}
}
/* public void mousePressed(MouseEvent e)
{
checkMenu(e);//自定義函數(shù),判斷是否是右鍵,來(lái)決定是否顯示菜單
}*/
public void mouseReleased(MouseEvent e)
{
checkMenu(e);//與上面的一樣,判斷是否鼠標(biāo)右鍵
}
}
);
//listB=new JLabel(new ImageIcon("qingdan.gif"),SwingConstants.CENTER);
scroll=new JScrollPane(list);//用于存放播放列表
//dialog2=new JDialogTest(MediaPlayer.this,"播放清單",scroll);
//dialog2.setVisible(true);
readToList.start();//啟動(dòng)先程,加載播放列表
try
{
Thread.sleep(10);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
/*look=UIManager.getInstalledLookAndFeels();
try
{
UIManager.setLookAndFeel(look[2].getClassName());
SwingUtilities.updateComponentTreeUI(this);
}
catch(Exception e)
{
e.printStackTrace();
}*///與下面的代碼實(shí)現(xiàn)相同的功能,但執(zhí)行速度要慢,原因:明顯轉(zhuǎn)了個(gè)大彎
/*try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
e.printStackTrace();
} *///此段代碼使執(zhí)行速度大大降低
bar=new JMenuBar();
setJMenuBar(bar);//此兩行創(chuàng)建菜單欄并放到此窗口程序
//bar.setBackground(new Color(48,91,183));
fileMenu=new JMenu("文件");
bar.add(fileMenu);
choiceMenu=new JMenu("控制");
bar.add(choiceMenu);
aboutMenu=new JMenu("幫助");
bar.add(aboutMenu);
openItem =new JMenuItem("打開(kāi)文件");
openDirItem =new JMenuItem("打開(kāi)目錄");
closeItem =new JMenuItem("退出程序");
openItem.addActionListener(this);
openDirItem.addActionListener(this);
closeItem.addActionListener(this);
fileMenu.add(openItem);
fileMenu.add(openDirItem);
fileMenu.add(closeItem);
onTop=new JCheckBoxMenuItem("播放時(shí)位于最前面",top);
choiceMenu.add(onTop);
onTop.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
if(onTop.isSelected())
top=true;
else top=false;
setAlwaysOnTop(top);
}
}
);
choiceMenu.addSeparator();//加分割符號(hào)
buttonGroup=new ButtonGroup();
buttonValues=new JRadioButtonMenuItem[3];
for(int bt=0;bt3;bt++)
{
buttonValues[bt]=new JRadioButtonMenuItem(content[bt]);
buttonGroup.add(buttonValues[bt]);
choiceMenu.add(buttonValues[bt]);
}
buttonValues[0].setSelected(true);
choiceMenu.addSeparator();
/*loopItem=new JCheckBoxMenuItem("是否循環(huán)");
choiceMenu.add(loopItem);
loopItem.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
loop=!loop;
}
}
);*/
infor=new JMenuItem("軟件簡(jiǎn)介");
aboutMenu.add(infor);
infor.addActionListener(this);
about=new JMenuItem("關(guān)于作者");
about.addActionListener(this);
aboutMenu.add(about);
//菜單欄設(shè)置完畢
panel=new JPanel();
panel.setLayout(new BorderLayout());
c.add(panel,BorderLayout.CENTER);
panelSouth=new JPanel();
panelSouth.setLayout(new BorderLayout());
c.add(panelSouth,BorderLayout.SOUTH);
icon=new ImageIcon("icon\\Player.jpg");
label=new JLabel(icon);
panel.add(label);
popupMenu=new JPopupMenu();
del =new JMenuItem("刪除");//鼠標(biāo)右鍵彈出菜單對(duì)象實(shí)例化
popupMenu.add(del);
del.addActionListener(this);
delAll =new JMenuItem("全部刪除");
popupMenu.add(delAll);
delAll.addActionListener(this);
reName =new JMenuItem("重命名");
popupMenu.add(reName);
reName.addActionListener(this);
scroll=new JScrollPane(list);//用于存放播放列表
listB=new JLabel(new ImageIcon("icon\\qingdan.gif"),SwingConstants.CENTER);
panelSouth.add(listB,BorderLayout.NORTH);
panelSouth.add(scroll,BorderLayout.CENTER);
dialog1=new DialogDemo(MediaPlayer.this,"軟件說(shuō)明");
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);//設(shè)定窗口關(guān)閉方式
//this.setTitle("d");編譯通過(guò),說(shuō)明可以再次設(shè)定標(biāo)題
this.setLocation(400,250);//設(shè)定窗口出現(xiàn)的位置
//this.setSize(350,320);//窗口大小
setSize(350,330);
this.setResizable(false);//設(shè)置播放器不能隨便調(diào)大小
this.setVisible(true);//此句不可少,否則窗口會(huì)不顯示
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==openItem)//getSource()判斷發(fā)生時(shí)間的組鍵
{
//System.out.println("d");測(cè)試用
openFile();
//createPlayer();
//setTitle(title);
}
if(e.getSource()==openDirItem)//打開(kāi)目錄
{
openDir();
}
if(e.getSource()==closeItem)//推出播放器
{
exity_n();
//System.exit(0);
}
if(e.getSource()==about)
{
JOptionPane.showMessageDialog(this,"此簡(jiǎn)易播放器由計(jì)科0302\n"
+"harly\n "+" 完成 ",
"參與者",
JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==del)
{
//index
//delPaintList(index);
fileName.removeElementAt(indexForDel);
dirName.removeElementAt(indexForDel);
numList.removeAllElements();//從三個(gè)容器里面移除此項(xiàng)
Enumeration enumFile=fileName.elements();
while(enumFile.hasMoreElements())
{
numList.addElement((numList.size()+1)+"."+enumFile.nextElement());
//numList添加元素,顯示播放里表中
}
//list.setListData(fileName);
list.setListData(numList);
if(indexindexForDel)
list.setSelectedValue(numList.elementAt(index),true);
else
{
if(index==indexForDel);
else
if(index!=0)
list.setSelectedValue(numList.elementAt(index-1),true);
}
//list.setSelectedIndex(index);
}
if(e.getSource()==delAll)//全部刪除
{
fileName.removeAllElements();
dirName.removeAllElements();
numList.removeAllElements();
list.setListData(numList);
}
if(e.getSource()==reName)//重命名
{
String name;//=JOptionPane.showInputDialog(this,"請(qǐng)輸入新的名字");
try
{
name=reNames();
fileName.setElementAt(name,indexForDel);
numList.setElementAt((indexForDel+1)+"."+name,indexForDel);
}
catch(ReName e2)//自定義的異常
{
}
}
if(e.getSource()==infor)
{
dialog1.setVisible(true);
}
}
public static void main(String[] args)
{
final MediaPlayer mp=new MediaPlayer();
mp.setIconImage(new ImageIcon("icon\\mPlayer.jpg").getImage());//改變默認(rèn)圖標(biāo)
mp.addWindowListener(new WindowAdapter()//注冊(cè)窗口事件
{
public void windowClosing(WindowEvent e)
{
//System.exit(0);
mp.exity_n();
}
}
);
System.out.println("注意:更新文件列表后,請(qǐng)先正常關(guān)閉播放器"
+"\n然后再關(guān)閉此DOS窗口,否則導(dǎo)致播放列表不能保存!!");
}
private void openFile()//為了界面原因,此代碼重寫,估計(jì)兼容性不好了
{
/*JFileChooser fileChooser=new JFileChooser();//文件選擇器
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);//可以選擇文件不能目錄
int result=fileChooser.showOpenDialog(this);//創(chuàng)建文件打開(kāi)對(duì)話框,并設(shè)定此程序?yàn)楦复翱诒O(jiān)控*/
/*通過(guò)result的值來(lái)判斷文件是否打開(kāi)成功
*JFileChooser類有很多靜態(tài)成員變量
**/
/*if(result==JFileChooser.CANCEL_OPTION)
{
file=null;//file已經(jīng)在類中定義,如果選擇取消,file指向?yàn)榭?/p>
}
else
{
file=fileChooser.getSelectedFile();//獲得文件對(duì)象
title=file.getAbsolutePath();//取得文件的絕對(duì)路徑并且賦給title設(shè)定標(biāo)題
}*/
//if(fd==null)
//{
//String filename="java音頻播放器";
fd = new FileDialog(MediaPlayer.this);
//Filters fl=new Filters();
//fd.setFilenameFilter(fl);
fd.setVisible(true);
if (fd.getFile() != null)
{
title = fd.getDirectory() + fd.getFile();//原因請(qǐng)見(jiàn)同目錄下的FileDialogDemo.java文件
files=fd.getFile();
//dir =fd.getDirectory();
file=new File(title);
createPlayer();
}
//title=filename;
//fd=null;//缺少此句如果第一次打開(kāi)文件的時(shí)候取消操作的時(shí)候第二次也不能打開(kāi)文件了
//}
}
private void openDir()
{
JFileChooser fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result=fileChooser.showOpenDialog(MediaPlayer.this);
if(result==JFileChooser.CANCEL_OPTION)
return;
file=fileChooser.getSelectedFile();
if(file==null||file.getName().equals(""))
JOptionPane.showMessageDialog(this,"錯(cuò)誤的路徑",
"出錯(cuò)了",JOptionPane.ERROR_MESSAGE);
String[] sFiles=file.list();
for(int i=0;isFiles.length;i++)
{
fileName.addElement(sFiles[i]);
numList.addElement((numList.size()+1)+"."+sFiles[i]);
dirName.addElement(file.getAbsolutePath()+"\\"+sFiles[i]);
}
list.setListData(numList);
/*fd=new FileDialog(MediaPlayer.this);
fd.setVisible(true);
if(fd.getDirectory()!=null)
{
File fileDir=new File(fd.getDirectory());
String[] ss=fileDir.list();
for(int i=0;iss.length;i++)
{
System.out.println(ss[i]);
}
}*/
}
請(qǐng)采納答案,支持我一下。
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FileDialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.ControllerClosedEvent;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.PrefetchCompleteEvent;
import javax.media.RealizeCompleteEvent;
import javax.media.Time;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class JMFMediaPlayer extends JFrame implements ActionListener,
ControllerListener, ItemListener {
// JMF的播放器
Player player;
// 播放器的視頻組件和控制組件
Component vedioComponent;
Component controlComponent;
// 標(biāo)示是否是第一次打開(kāi)播放器
boolean first = true;
// 標(biāo)示是否需要循環(huán)
boolean loop = false;
// 文件當(dāng)前目錄
String currentDirectory;
// 構(gòu)造方法
public JMFMediaPlayer(String title) {
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
// 用戶點(diǎn)擊窗口系統(tǒng)菜單的關(guān)閉按鈕
// 調(diào)用dispose以執(zhí)行windowClosed
dispose();
}
public void windowClosed(WindowEvent e){
if (player != null){
// 關(guān)閉JMF播放器對(duì)象
player.close();
}
System.exit(0);
}
});
// 創(chuàng)建播放器的菜單
JMenu fileMenu = new JMenu("文件");
JMenuItem openMemuItem = new JMenuItem("打開(kāi)");
openMemuItem.addActionListener(this);
fileMenu.add(openMemuItem);
// 添加一個(gè)分割條
fileMenu.addSeparator();
// 創(chuàng)建一個(gè)復(fù)選框菜單項(xiàng)
JCheckBoxMenuItem loopMenuItem = new JCheckBoxMenuItem("循環(huán)", false);
loopMenuItem.addItemListener(this);
fileMenu.add(loopMenuItem);
fileMenu.addSeparator();
JMenuItem exitMemuItem = new JMenuItem("退出");
exitMemuItem.addActionListener(this);
fileMenu.add(exitMemuItem);
JMenuBar menuBar = new JMenuBar();
menuBar.add(fileMenu);
this.setJMenuBar(menuBar);
this.setSize(200, 200);
try {
// 設(shè)置界面的外觀,為系統(tǒng)外觀
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
e.printStackTrace();
}
this.setVisible(true);
}
/**
* 實(shí)現(xiàn)了ActionListener接口,處理組件的活動(dòng)事件
*/
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("退出")) {
// 調(diào)用dispose以便執(zhí)行windowClosed
dispose();
return;
}
FileDialog fileDialog = new FileDialog(this, "打開(kāi)媒體文件", FileDialog.LOAD);
fileDialog.setDirectory(currentDirectory);
fileDialog.setVisible(true);
// 如果用戶放棄選擇文件,則返回
if (fileDialog.getFile() == null){
return;
}
currentDirectory = fileDialog.getDirectory();
if (player != null){
// 關(guān)閉已經(jīng)存在JMF播放器對(duì)象
player.close();
}
try {
// 創(chuàng)建一個(gè)打開(kāi)選擇文件的播放器
player = Manager.createPlayer(new MediaLocator("file:"
+ fileDialog.getDirectory() + fileDialog.getFile()));
} catch (java.io.IOException e2) {
System.out.println(e2);
return;
} catch (NoPlayerException e2) {
System.out.println("不能找到播放器.");
return;
}
if (player == null) {
System.out.println("無(wú)法創(chuàng)建播放器.");
return;
}
first = false;
this.setTitle(fileDialog.getFile());
// 播放器的控制事件處理
player.addControllerListener(this);
// 預(yù)讀文件內(nèi)容
player.prefetch();
}
/**
* 實(shí)現(xiàn)ControllerListener接口的方法,處理播放器的控制事件
*/
public void controllerUpdate(ControllerEvent e) {
// 調(diào)用player.close()時(shí)ControllerClosedEvent事件出現(xiàn)。
// 如果存在視覺(jué)部件,則該部件應(yīng)該拆除(為一致起見(jiàn),
// 我們對(duì)控制面板部件也執(zhí)行同樣的操作)
if (e instanceof ControllerClosedEvent) {
if (vedioComponent != null) {
this.getContentPane().remove(vedioComponent);
this.vedioComponent = null;
}
if (controlComponent != null) {
this.getContentPane().remove(controlComponent);
this.controlComponent = null;
}
return;
}
// 如果是媒體文件到達(dá)尾部事件
if (e instanceof EndOfMediaEvent) {
if (loop) {
// 如果允許循環(huán),則重新開(kāi)始播放
player.setMediaTime(new Time(0));
player.start();
}
return;
}
// 如果是播放器預(yù)讀事件
if (e instanceof PrefetchCompleteEvent) {
// 啟動(dòng)播放器
player.start();
return;
}
// 如果是文件打開(kāi)完全事件,則顯示視頻組件和控制器組件
if (e instanceof RealizeCompleteEvent) {
vedioComponent = player.getVisualComponent();
if (vedioComponent != null){
this.getContentPane().add(vedioComponent);
}
controlComponent = player.getControlPanelComponent();
if (controlComponent != null){
this.getContentPane().add(controlComponent, BorderLayout.SOUTH);
}
this.pack();
}
}
// 處理“循環(huán)”復(fù)選框菜單項(xiàng)的點(diǎn)擊事件
public void itemStateChanged(ItemEvent e) {
loop = !loop;
}
public static void main(String[] args){
new JMFMediaPlayer("JMF媒體播放器");
}
}
試試吧,我這里運(yùn)行正常
視頻也是一個(gè)文件,就用file類就可以了,這里簡(jiǎn)單幫你實(shí)現(xiàn)一下吧:
---------------------------
//向該方法傳遞視頻文件的路徑
public static void getVideo(String filePath){
//得到一個(gè)File 對(duì)象
File fileImg=FraudinfoAction.getFraudImg(path);
//渲染一個(gè)二進(jìn)制字節(jié)碼文件
renderBinary(fileImg);
}
下載JMF(java media framework)
下面是一個(gè)例子
import?java.awt.BorderLayout;
import?java.awt.Component;
import?java.net.MalformedURLException;
import?java.net.URL;
import?javax.media.Manager;
import?javax.media.MediaLocator;
import?javax.media.Player;
import?javax.swing.JFileChooser;
import?javax.swing.JFrame;
public?class?MediaPlayer?extends?javax.swing.JPanel?{
public?MediaPlayer(URL?mediauUrl)?{???????
initComponents();
setLayout(new?BorderLayout());
try?{
Player?mediaPlayer?=?Manager.createRealizedPlayer(new?MediaLocator(mediauUrl));
Component?video?=?mediaPlayer.getVisualComponent();
Component?control?=?mediaPlayer.getControlPanelComponent();
if?(video?!=?null)?{
add(video,?BorderLayout.CENTER);??????????//?place?the?video?component?in?the?panel
}
add(control,?BorderLayout.SOUTH);????????????//?place?the?control?in??panel
mediaPlayer.start();
}?catch?(Exception?e)?{
}
}
private?void?initComponents()?{
javax.swing.GroupLayout?layout?=?new?javax.swing.GroupLayout(getTopLevelAncestor());
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0,?720,?Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0,?480,?Short.MAX_VALUE)
);
}
public?static?void?main(String[]?args)?{
JFileChooser?fileChooser?=?new?JFileChooser();
fileChooser.showOpenDialog(null);
URL?mediaUrl?=?null;
try?{
mediaUrl?=?fileChooser.getSelectedFile().toURI().toURL();
}?catch?(MalformedURLException?ex)?{
System.out.println(ex);
}
JFrame?mediaTest?=?new?JFrame("Movie?Player");
mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MediaPlayer?mediaPanel?=?new?MediaPlayer(mediaUrl);
mediaTest.add(mediaPanel);
mediaTest.setSize(800,?700);?//?set?the?size?of?the?player
mediaTest.setLocationRelativeTo(null);
mediaTest.setVisible(true);
}
}
在后臺(tái),java中根據(jù)路徑找目錄下所有的視頻文件,然后把名字和url返回到前臺(tái),前臺(tái)顯示列表,點(diǎn)擊后打開(kāi)播放頁(yè),網(wǎng)上很多flash制作的播放器,嵌入到網(wǎng)頁(yè)中并把視頻url傳遞進(jìn)去就可以了。博客noday.net我若有時(shí)間就寫個(gè)例子