導航:首頁 > 編程語言 > 用java寫視頻播放器

用java寫視頻播放器

發布時間:2023-02-07 17:08:22

java用JMF編寫的視頻播放器播放本地文件只有聲音沒有圖像,求解啊!!!

需要安裝對應的解碼器 (decoder),JMF 本身並不自帶所有的解碼器,跟 Windows Media Player 一樣,它也是查找系統中注冊過的解碼器,你用 Windows Media Player 來播放估計也是一樣只有聲音沒有圖像。

我們可以在網上搜索常用的解碼器(只是解碼器不包含播放器)來安裝。

⑵ 用java開發一個視頻播放器需要用到哪些知識

我也在做這個,其實很簡單,如果你不需要支持很多的視頻格式。運用java的多媒體開發包JMF就能很快地開發到一個簡單的播放器。JMF支持的文件格式有mpeg,avi等。我有例子,可以發給你。

⑶ 用java寫的視頻播放器 運行是出現 java.lang.NoClassDefFoundError: com/videoexample/PlayVideo

com/videoexample/PlayVideo這個目錄是你自己創建的么,如果是的.就是找不到你的類了.
路徑問題, 如果不是,那就是缺少包含PlayVideo的jar包,網路一下就行了.就搜索包含PlayVideo的jar包

⑷ 用java如何做一個視頻播放器

package JMF;
import javax.media.*;
import java.net.*;
public class SPlayer
{
public static void main(String [] args)
{
try
{
URL location = SPlayer.class.getResource("name.mp3"); //同目錄下文件
MediaLocator mrl = new MediaLocator(location);
Player player = Manager.createPlayer(mrl);
player.start();
}
catch (Exception e)
{
System.out.println("Error: "+e.toString());
}
}
}

參數:
name - 所需資源的名稱
返回:
一個 URL 對象;如果找不到帶有該名稱的內資源,則容返回 null

⑸ 求JAVA視頻播放器代碼

可以的,到官網視頻課程頁面下載即可,不用一下在全下下來,如版果是基礎可以先去B站上看老權杜的新班基礎教程,先把Java環境配置了。動力節點的java基礎教程159集,20年最新升級為全新的java基礎316集,可以通過蛙課網獲取哦
要好的培訓機構,那推薦,專門培訓JAVA的,數十年辦學經驗,目前它們的火熱招募學員中,快點去看看

⑹ 用java做音視頻播放器

我做過一個MP3的..給你看看.

package music;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.media.bean.playerbean.*; //這個包要用到JMF

public class MP3 extends JFrame implements Runnable {
public JLabel shijian;

private JSlider sldDiameter;

public MediaPlayer soumd1;

public JButton playSound, loopSound, stopsound;

public JButton tjian, shanc, baocun, qu;

public JPanel jp1, jp2, jp3, jp4;

public JList jl;

int zongmiao=0;

public Vector vector, mingcheng;

boolean fo = false, geshi = false;

JLabel jl1, jl2, sj1, sj2;

JTextField jt1, jt2;

JButton queding, xiugai;

int zong = 0;

int a = 0, b = 0, you = 1,mm=0;

int fenzhong, miaozhong;

public MP3() {
super(「java簡單音樂播放器「);
soumd1 = new MediaPlayer();
Container c = getContentPane();
c.setLayout(new FlowLayout());
mingcheng = new Vector();
jp1 = new JPanel();
shijian = new JLabel();
jp1.add(shijian);
c.add(jp1);
playSound = new JButton(「開始播放「);
loopSound = new JButton(「循環播放「);
stopsound = new JButton(「停止播放「);
jp2 = new JPanel();
jp2.add(playSound);
jp2.add(loopSound);
jp2.add(stopsound);
c.add(jp2);
jp4 = new JPanel();
sj1 = new JLabel();
sj2 = new JLabel();
sldDiameter = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 0);
sldDiameter.setMajorTickSpacing(1);
sldDiameter.setPaintTicks(true);
jp4.add(sj1);
jp4.add(sldDiameter);
jp4.add(sj2);
c.add(jp4);
vector = new Vector();
jl = new JList(mingcheng);
jl.setVisibleRowCount(5);
jl.setFixedCellHeight(40);
jl.setFixedCellWidth(265);
jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
c.add(new JScrollPane(jl));
tjian = new JButton(「添加「);
shanc = new JButton(「刪除「);
qu = new JButton(「讀取「);
baocun = new JButto

摘選自網上,希望對你有幫助。

⑺ 使用Java基於vlc製作視頻播放器

vlc.exe xxx.mp4
xxx.mp4就是要播放的視頻,文件、url都可以
直接用Runtime.exec....執行這個命令就行
vlc.exe、視頻路徑必須是絕對路徑

⑻ 用java編視頻播放器需要用那個類庫支持

編寫一個視頻播放器,要用到sun開發的一個附加的API包,即JMF API包,全稱是Java Media Framework API。這個包不是J2SE SDK中的標准包,在安裝JDK的時候是不含這個包的,那麼這個包可以去sun網站上下載,並且在你所使用的IDE中添加即可,那麼具體下載網站是:
http://java.sun.com/procts/java-media/jmf/2.1.1/download.html
可以查看一下新的版本
另外,幫助文檔可以在http://java.sun.com/procts/java-media/jmf/2.1.1/documentation.html上下載。
希望對樓主有所幫助!

⑼ java課題設計——視頻播放器怎麼製作

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;import javax.swing.*;
import javax.media.*;public class VideoPlayer extends JFrame implements ActionListener,
ControllerListener {
FileDialog fd;
Player player = null;
String name;
String path;
Component comp, vc;
Image image=new ImageIcon("open.GIF").getImage();
MenuBar mb = new MenuBar();
Menu m1 = new Menu("文件");
Menu m2 = new Menu("幫助");
MenuItem mi1 = new MenuItem("打開", new MenuShortcut(KeyEvent.VK_0));
MenuItem mi2 = new MenuItem("關閉");
MenuItem mi3 = new MenuItem("幫助");
JButton open=new JButton(new ImageIcon("open.GIF")); public VideoPlayer() {
super("視屏播放器");
this.setMenuBar(mb);
mb.add(m1);
mb.add(m2);
m1.add(mi1);
mi1.addActionListener(this);
m1.add(mi2);
mi2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
m2.add(mi3);
mi3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"Java視屏播放器\n2010年6月9日第一版\n製作人: 李攀");
}
});
this.setLayout(new BorderLayout());
this.setSize(800, 650);
this.setVisible(true);
this.setBackground(Color.BLACK);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} public static void main(String[] args) {
new VideoPlayer();
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == mi1) {
open();
}
} public void open() {
fd = new FileDialog(this, "打開媒體文件", FileDialog.LOAD);
fd.setVisible(true);
path = fd.getDirectory();
name = fd.getFile();
if (!path.equals("") && path != null) {
try {
if (player != null)
player.close();
player = Manager.createPlayer(new MediaLocator("file:" + path
+ name));
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "獲取播放器失敗!");
}
player.addControllerListener(this);
player.prefetch();
player.start();
}
} public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, 800, 650);
g.setColor(Color.GREEN);
g.setFont(new Font("宋體",Font.BOLD,30));
g.drawString("歡迎使用",340,150);
g.drawImage(image,330,285,image.getWidth(this),image.getHeight(this),this);
}
public void update(Graphics g){
paint(g);
} public synchronized void controllerUpdate(ControllerEvent e) {
if (e instanceof RealizeCompleteEvent) {
if ((comp = player.getControlPanelComponent()) != null) {
vc = player.getVisualComponent();
if (vc != null)
add(vc);
add("South", comp);
comp.setBackground(Color.green);
}
validate();
}
if (e instanceof ControllerClosedEvent) {
if (vc != null) {
remove(vc);
vc = null;
}
if (comp != null) {
remove(comp);
comp = null;
}
return;
}
if (e instanceof EndOfMediaEvent) {
player.setMediaTime(new Time(0));
player.start();
return;
}
}
}
java的視屏播放要用到JMF(java media framework),你自己到網上去下一個嘛,而且那玩意支持的格式少,mpg,mpeg,sun的官方網站說支持AVI但是我試過了好像不行,至於rmvb那些好像不行,要裝解碼器。JMF在安裝的時候要安裝對哦,路徑要選擇對,不然不行,具體下載地址和安裝方法可以網路一下,到處都是

⑽ 求Java編寫的視頻播放器程序

不全~代碼發不了了~,剩下的是播放器的關閉以及播放格式的支持與否,不麻煩的自己寫吧
MediaPlayer.java
----------------------------------------------------------------------------
//程序主文件
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.*;
import java.io.*;
import java.util.*;//為了導入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;//設定窗口是否在最前面
private Player player;//Play是個實現Controller的介面
private File file,listFile;//利用File類結合JFileChooser進行文件打開操作,後則與list.ini有關
private Container c;
//private UIManager.LookAndFeelInfo[] look;
private String title,listIniAddress;//標題
private FileDialog fd;
private JPanel panel,panelSouth;
private Icon icon; //開始進入的時候要顯示的圖標,它為抽象類,不能自己創建
private JLabel label,listB;//用來顯示圖標

private JList list;//播放清單
private JScrollPane scroll;//使播放清單具有滾動功能
private ListValues listWriteFile;//用於向文件中讀取對象
private ObjectInputStream input;//對象輸入流
private ObjectOutputStream output;//對象輸出流

private JPopupMenu popupMenu;//滑鼠右鍵彈出菜單
private JMenuItem del,delAll,reName; //彈出菜單顯示的菜單項,包括刪除,全部刪除和重命名

private Vector fileName,dirName,numList;
private String files,dir;
private int index;//曲目指針
private Properties prop;//獲得系統屬性
private int indexForDel;//標志要刪除的列表項目的索引
private ButtonGroup buttonGroup;//控制按鈕組
private JRadioButtonMenuItem[] buttonValues;
private String[] content={"隨機播放","順序播放","單曲循環"};

private DialogDemo dialog1;
//private JDialogTest dialog2;//用於顯示播放清單

MediaPlayer()//構造函數
{
super("java音頻播放器1.1版");//窗口標題

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);//構造三個容器用於支持播放清單
//vectorToString=new String[];
//prop=new Properties(System.getProperties());
//listIniAddress=prop.getProperty("user.dir")+"\\list.ini";
//listFile=new File(listIniAddress);//本來這些代碼用來取的系統屬性,後來
//發現根本就不用這么麻煩
listFile=new File("list.ini");//直接存於此目錄
Thread readToList=new Thread(this);//注意編線程程序的時候要注意運行的時候含有的變數億定義或者初始化,
//這就要求線程要等上述所說的情況下再運行,否則很容易發生錯誤或則異常

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("點右鍵顯示更多功能");//創建播放清單並設置各個屬性
list.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2) //判斷是否雙擊
{
index = list.locationToIndex(e.getPoint());//將滑鼠坐標轉化成list中的選項指針
createPlayer2();
//System.out.println("Double clicked on Item " + index);,此是測試的時候加的
}
}
/* public void mousePressed(MouseEvent e)
{
checkMenu(e);//自定義函數,判斷是否是右鍵,來決定是否顯示菜單
}*/
public void mouseReleased(MouseEvent e)
{
checkMenu(e);//與上面的一樣,判斷是否滑鼠右鍵
}

}
);
//listB=new JLabel(new ImageIcon("qingdan.gif"),SwingConstants.CENTER);
scroll=new JScrollPane(list);//用於存放播放列表
//dialog2=new JDialogTest(MediaPlayer.this,"播放清單",scroll);
//dialog2.setVisible(true);

readToList.start();//啟動先程,載入播放列表
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();
}*///與下面的代碼實現相同的功能,但執行速度要慢,原因:明顯轉了個大彎

/*try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
e.printStackTrace();
} *///此段代碼使執行速度大大降低

bar=new JMenuBar();
setJMenuBar(bar);//此兩行創建菜單欄並放到此窗口程序
//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("打開文件");
openDirItem =new JMenuItem("打開目錄");
closeItem =new JMenuItem("退出程序");
openItem.addActionListener(this);
openDirItem.addActionListener(this);
closeItem.addActionListener(this);
fileMenu.add(openItem);
fileMenu.add(openDirItem);
fileMenu.add(closeItem);

onTop=new JCheckBoxMenuItem("播放時位於最前面",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();//加分割符號

buttonGroup=new ButtonGroup();
buttonValues=new JRadioButtonMenuItem[3];
for(int bt=0;bt<3;bt++)
{
buttonValues[bt]=new JRadioButtonMenuItem(content[bt]);
buttonGroup.add(buttonValues[bt]);
choiceMenu.add(buttonValues[bt]);
}
buttonValues[0].setSelected(true);
choiceMenu.addSeparator();

/*loopItem=new JCheckBoxMenuItem("是否循環");
choiceMenu.add(loopItem);
loopItem.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
loop=!loop;
}
}
);*/
infor=new JMenuItem("軟體簡介");
aboutMenu.add(infor);
infor.addActionListener(this);

about=new JMenuItem("關於作者");
about.addActionListener(this);
aboutMenu.add(about);
//菜單欄設置完畢

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("刪除");//滑鼠右鍵彈出菜單對象實例化
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,"軟體說明");

this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);//設定窗口關閉方式
//this.setTitle("d");編譯通過,說明可以再次設定標題
this.setLocation(400,250);//設定窗口出現的位置
//this.setSize(350,320);//窗口大小
setSize(350,330);
this.setResizable(false);//設置播放器不能隨便調大小
this.setVisible(true);//此句不可少,否則窗口會不顯示

}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==openItem)//getSource()判斷發生時間的組鍵
{
//System.out.println("d");測試用
openFile();
//createPlayer();
//setTitle(title);

}
if(e.getSource()==openDirItem)//打開目錄
{
openDir();
}
if(e.getSource()==closeItem)//推出播放器
{
exity_n();
//System.exit(0);
}
if(e.getSource()==about)
{
JOptionPane.showMessageDialog(this,"此簡易播放器由計科0302\n"
+"harly\n "+" 完成 ",
"參與者",
JOptionPane.INFORMATION_MESSAGE);
}
if(e.getSource()==del)
{
//index
//delPaintList(index);
fileName.removeElementAt(indexForDel);
dirName.removeElementAt(indexForDel);
numList.removeAllElements();//從三個容器裡面移除此項
Enumeration enumFile=fileName.elements();
while(enumFile.hasMoreElements())
{
numList.addElement((numList.size()+1)+"."+enumFile.nextElement());
//numList添加元素,顯示播放里表中
}
//list.setListData(fileName);
list.setListData(numList);
if(index<indexForDel)
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,"請輸入新的名字");
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());//改變默認圖標
mp.addWindowListener(new WindowAdapter()//注冊窗口事件
{
public void windowClosing(WindowEvent e)
{
//System.exit(0);
mp.exity_n();
}
}

);
System.out.println("注意:更新文件列表後,請先正常關閉播放器"
+"\n然後再關閉此DOS窗口,否則導致播放列表不能保存!!");
}

private void openFile()//為了界面原因,此代碼重寫,估計兼容性不好了
{
/*JFileChooser fileChooser=new JFileChooser();//文件選擇器
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);//可以選擇文件不能目錄
int result=fileChooser.showOpenDialog(this);//創建文件打開對話框,並設定此程序為父窗口監控*/

/*通過result的值來判斷文件是否打開成功
*JFileChooser類有很多靜態成員變數
**/
/*if(result==JFileChooser.CANCEL_OPTION)
{
file=null;//file已經在類中定義,如果選擇取消,file指向為空
}
else
{
file=fileChooser.getSelectedFile();//獲得文件對象
title=file.getAbsolutePath();//取得文件的絕對路徑並且賦給title設定標題
}*/
//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();//原因請見同目錄下的FileDialogDemo.java文件
files=fd.getFile();
//dir =fd.getDirectory();
file=new File(title);
createPlayer();

}
//title=filename;
//fd=null;//缺少此句如果第一次打開文件的時候取消操作的時候第二次也不能打開文件了
//}
}
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,"錯誤的路徑",
"出錯了",JOptionPane.ERROR_MESSAGE);
String[] sFiles=file.list();
for(int i=0;i<sFiles.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;i<ss.length;i++)
{
System.out.println(ss[i]);
}
}*/
}
請採納答案,支持我一下。

閱讀全文

與用java寫視頻播放器相關的資料

熱點內容
國際在線觀看的網站 瀏覽:219
alienwarewin10系統盤 瀏覽:558
男主抓女當鼎爐的小說 瀏覽:9
韓國電影有一對雙胞胎兄弟 瀏覽:657
wav文件編輯 瀏覽:533
華為手機如何把app圖標變大 瀏覽:488
lumion6視頻教程下載 瀏覽:234
1080p電影網站 瀏覽:733
maya各版本下載地址 瀏覽:129
百合片網站 瀏覽:213
有個韓劇醫生殺人有個女主角叫珠蘭 瀏覽:803
美國網路為什麼會癱瘓 瀏覽:528
韓劇女主經常頭暈男主是消防員 瀏覽:781
蘋果app必須充值50嗎 瀏覽:624
魁拔那年上影 瀏覽:888
法國啄木鳥絲襪電影 瀏覽:954
快來看看我給你分享的網站:播放短視頻 瀏覽:869
男主是廢材,有個小娃娃拿槍的日漫 瀏覽:609
雁江區大數據 瀏覽:617
ps教程插入文字 瀏覽:444

友情鏈接