导航:首页 > 编程语言 > 用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写视频播放器相关的资料

热点内容
怎么用c编程平台 浏览:527
编程里n怎么表示正整数 浏览:391
微信聊天记录存储的文件夹 浏览:590
iphone5s基带版本查询 浏览:548
江阴证件文件翻译多少钱 浏览:316
javaruntime142 浏览:610
word把数字变斜 浏览:372
小米6忘记锁屏密码怎么办啊 浏览:462
北京白领都用什么社交app 浏览:518
政法app哪个好用 浏览:514
房产平台如何推广新网站 浏览:701
u盘导文件总是中断 浏览:995
下载的招标文件打不开是为什么 浏览:356
都市美艳后宫 浏览:435
十部顶级古埃及电影 浏览:107
linux用户读写权限 浏览:936
少侠十七妻全文阅读 浏览:422
公主奴 浏览:856
k9d3 浏览:182
分卷阅读 玩武警少尉 浏览:44

友情链接