import java.awt.*;
import java.awt.event.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.protocol.*;
public class JMF extends Frame implements ActionListener, ItemListener, WindowListener,
ControllerListener {
CaptureDeviceInfo audioCDI = null;
CaptureDeviceInfo videoCDI = null;
String audioDeviceName = null;
String videoDeviceName = null;
Player videoPlayer;
Player audioPlayer;
Format videoFormat;
Format audioFormat;
Player dualPlayer; //for merging audio and video data sources
DataSource dataSource; //of the capture devices
public JMF(String title) {
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dispose();
}
});
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menuAction = new Menu("Arquivo");
mb.add(menuAction);
/* menu items for Action */
MenuItem a2 = new MenuItem("Abrir");
a2.addActionListener(this);
menuAction.add(a2);
MenuItem a3 = new MenuItem("Parar");
a3.addActionListener(this);
menuAction.add(a3);
}
public void actionPerformed(ActionEvent ae) {
String command = ae.getActionCommand().toString();
if (command.equals("Abrir")) {
play();
} else if (command.equals("Parar")) {
stop();
}
}
void play() {
Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
Format input2 = new AudioFormat(AudioFormat.MPEG);
Format output = new AudioFormat(AudioFormat.LINEAR);
PlugInManager.addPlugIn(
"com.sun.media.codec.audio.mp3.JavaDecoder",
new Format[]{input1, input2},
new Format[]{output},
PlugInManager.CODEC
);
try {
FileDialog fd = new FileDialog(this, "Select File", FileDialog.LOAD);
fd.show();
String filename = fd.getDirectory() + fd.getFile();
dualPlayer = Manager.createPlayer(new MediaLocator("file:///" + filename));
System.out.println("Adding controller listener");
dualPlayer.addControllerListener(this);
System.out.println("Starting player ...");
dualPlayer.start();
}
catch (Exception e) {
System.out.println(e.toString());
}
}
void stop() {
if (dualPlayer!=null) {
dualPlayer.stop();
dualPlayer.deallocate();
}
}
public synchronized void controllerUpdate(ControllerEvent event) {
System.out.println(event.toString());
if (event instanceof RealizeCompleteEvent) {
Component comp;
System.out.println("Adding visual component");
if ((comp = dualPlayer.getVisualComponent()) != null)
add ("Center", comp);
System.out.println("Adding control panel");
if ((comp = dualPlayer.getControlPanelComponent()) != null)
add("South", comp);
validate();
}
}
public void itemStateChanged(ItemEvent ie) {}
public void windowActivated(WindowEvent we) {}
public void windowClosed(WindowEvent we) {}
public void windowClosing(WindowEvent we) {}
public void windowDeactivated(WindowEvent we) {}
public void windowDeiconified(WindowEvent we) {}
public void windowIconified(WindowEvent we) {}
public void windowOpened(WindowEvent we) {}
public static void main(String[] argv) {
JMF myFrame = new JMF("Java Media Framework Project");
myFrame.show();
myFrame.setSize(300, 300);
}
}
JMF.rar_jmf_player
版权申诉
154 浏览量
2022-09-23
13:34:56
上传
评论
收藏 5KB RAR 举报
weixin_42651887
- 粉丝: 75
- 资源: 1万+
最新资源
- 126641091882064LSPatch.apk
- 5G网络基础培训课件.zip
- 2024-spring-HIT-CS-大作业
- yolo目标检测项目实验
- downloadFile-1.hc
- C++课程设计:基于Qt的航班信息管理系统
- ADS7822UVerilog驱动,前面传的有点问题
- 基于python的高性能爬虫程序,使用了多线程+缓存+xpath实现的,这里以彼-岸图库为例,实现,仅用于学习交流
- 中分辨率成像光谱仪(MODIS)烧毁面积产品信息MODIS-C6-BA-User-Guide-1.2.pdf
- Screenshot_20240427_172613_com.huawei.browser.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈