swing如何播放视屏文件???
jmf可以播放视屏 但是我这里文件拿过来就是mp4格式的 不可能让我中间去转码吧。。。。
java除了jmf还有别的方式可以播放视屏文件的没??
[最优解释]
不一定非要使用jmf,只是建议:
http://blog.csdn.net/geminit2011/article/details/7682879
这是我写的,其中的NativeSwing中有一个vlc player可以实现播放mp4。
代码:
/*
* Christopher Deckers (chrriis@nextencia.net)
* http://www.nextencia.net
*
* See the file "readme.txt" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
package chrriis.dj.nativeswing.swtimpl.demo.examples.vlcplayer;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JVLCPlayer;
/**
* @author Christopher Deckers
*/
public class SimpleVLCPlayerExample extends JPanel {
public SimpleVLCPlayerExample() {
super(new BorderLayout());
// Create the player.
JPanel playerPanel = new JPanel(new BorderLayout());
playerPanel.setBorder(BorderFactory.createTitledBorder("VLC Player component"));
final JVLCPlayer player = new JVLCPlayer();
playerPanel.add(player, BorderLayout.CENTER);
add(playerPanel, BorderLayout.CENTER);
// Create the components that allow to load a file in the player.
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints cons = new GridBagConstraints();
JPanel playerFilePanel = new JPanel(gridBag);
JLabel playerFileLabel = new JLabel("File: ");
cons.gridx = 0;
cons.gridy = 0;
cons.insets = new Insets(2, 2, 2, 0);
cons.fill = GridBagConstraints.HORIZONTAL;
gridBag.setConstraints(playerFileLabel, cons);
playerFilePanel.add(playerFileLabel);
final JTextField playerFileTextField = new JTextField();
cons.gridx++;
cons.weightx = 1;
gridBag.setConstraints(playerFileTextField, cons);
final Runnable loadPlayerFileRunnable = new Runnable() {
public void run() {
player.load(playerFileTextField.getText());
}
};
playerFileTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loadPlayerFileRunnable.run();
}
});
playerFilePanel.add(playerFileTextField);
JButton playerFileButton = new JButton("...");
cons.gridx++;
cons.insets = new Insets(2, 2, 2, 2);
cons.weightx = 0;
gridBag.setConstraints(playerFileButton, cons);
playerFileButton.addActionListener(new ActionListener() {
JFileChooser fileChooser;
public void actionPerformed(ActionEvent e) {
if(fileChooser == null) {
fileChooser = new JFileChooser();
}
if(fileChooser.showOpenDialog(SimpleVLCPlayerExample.this) == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
playerFileTextField.setText(selectedFile.getAbsolutePath());
loadPlayerFileRunnable.run();
}
}
});
playerFilePanel.add(playerFileButton);
add(playerFilePanel, BorderLayout.NORTH);
// Create an additional bar allowing to show/hide the control bar of the Flash player.
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));
player.setControlBarVisible(false);
JCheckBox controlBarCheckBox = new JCheckBox("Control Bar");
controlBarCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
player.setControlBarVisible(e.getStateChange() == ItemEvent.SELECTED);
}
});
buttonPanel.add(controlBarCheckBox);
add(buttonPanel, BorderLayout.SOUTH);
}
/* Standard main method to try that test as a standalone application. */
public static void main(String[] args) {
UIUtils.setPreferredLookAndFeel();
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("DJ Native Swing Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new SimpleVLCPlayerExample(), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
NativeInterface.runEventPump();
}
}
at StreamingMediaPlayer.start(StreamingMediaPlayer.java:722)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
... 1 more
[其他解释]
你不看文档。Media的参数是一个URI格式的字符串。支持 http、file、jar协议。
http://............mp4
file:/.........mp4
上面那个写错了
new Media("file:/D:/Temp/LaTeXDraw2.0.8/data/LaTeXDraw.avi")
[其他解释]
目前只支持flv,mp3和一些http的流媒体而已……mp4尚不在其支持的范围之内。
[其他解释]
package media.player;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaPlayer.Status;
import javafx.scene.media.MediaView;
import javafx.util.Duration;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
public class MediaControl extends BorderPane {
private MediaPlayer mp;
private MediaView mediaView;
private final boolean repeat = false;
private boolean stopRequested = false;
private boolean atEndOfMedia = false;
private Duration duration;
private Slider timeSlider;
private Label playTime;
private Slider volumeSlider;
private HBox mediaBar;
public MediaControl(final MediaPlayer mp) {
this.mp = mp;
setStyle("-fx-background-color: #bfc2c7;");
mediaView = new MediaView(mp);
Pane mvPane = new Pane() {
};
mvPane.getChildren().add(mediaView);
mvPane.setStyle("-fx-background-color: black;");
setCenter(mvPane);
mediaBar = new HBox();
mediaBar.setAlignment(Pos.CENTER);
mediaBar.setPadding(new Insets(5, 10, 5, 10));
BorderPane.setAlignment(mediaBar, Pos.CENTER);
final Button playButton = new Button(">");
mediaBar.getChildren().add(playButton);
playButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
Status status = mp.getStatus();
if (status == Status.UNKNOWN
[其他解释]
oracle官网关于javafx支持media的代码demo
package media.player;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
public class EmbeddedMediaPlayer extends Application {
private static final String MEDIA_URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Embedded Media Player");
Group root = new Group();
Scene scene = new Scene(root, 540, 210);
primaryStage.setScene(scene);
primaryStage.show();
// create media player
Media media = new Media(MEDIA_URL);
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
// create mediaView and add media player to the viewer
MediaView mediaView = new MediaView(mediaPlayer);
((Group) scene.getRoot()).getChildren().add(mediaView);
MediaControl mediaControl = new MediaControl(mediaPlayer);
scene.setRoot(mediaControl);
}
public static void main(String[] args) {
Application.launch(args);
}
}
[其他解释]
status == Status.HALTED) {
// don't do anything in these states
return;
}
if (status == Status.PAUSED