首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

swing怎么播放视屏文件?

2012-12-28 
swing如何播放视屏文件???jmf可以播放视屏 但是我这里文件拿过来就是mp4格式的 不可能让我中间去转码吧。。。

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();
  }

}


附上截图:



[其他解释]
什么错误?

new Media(mediafile.toURI())
[其他解释]
javax.media.NoPlayerException: Cannot find a Player for :file:C:\DownLoad\192.168.1.1681Time20121123090000Time20121123090010.mp4
at javax.media.Manager.createPlayerForContent(Manager.java:1412)
at javax.media.Manager.createPlayer(Manager.java:417)
at VideoPlayer.open(VideoPlayer.java:74)
at VideoPlayer.actionPerformed(VideoPlayer.java:61)
at java.awt.MenuItem.processActionEvent(MenuItem.java:627)
at java.awt.MenuItem.processEvent(MenuItem.java:586)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:337)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:325)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:651)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:621)
at java.awt.EventQueue$2.run(EventQueue.java:619)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)



如上报错  也翻阅了相关资料 没看到jmf支持mp4  mp3文件皆可播放
[其他解释]
引用:
不一定非要使用jmf,只是建议:
http://blog.csdn.net/geminit2011/article/details/7682879
这是我写的,其中的NativeSwing中有一个vlc player可以实现播放mp4。
代码:Java code?1234567891011121314151617181920212223242526272829303……



import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JVLCPlayer;
 

JVLCPlayer
这些类是哪个jar包里的 ?
[其他解释]
你一定没看我的博文,你上网下载
地址:http://djproject.sourceforge.net/ns/
------其他解决方案--------------------


下载不行就等会上我的资源去下载 我传上去了 估计要审批一会 叫swt jar包
[其他解释]
好的 我先试试 谢
[其他解释]
不使用swing,使用 javafx,自带多媒体播放。
[其他解释]

引用:
不使用swing,使用 javafx,自带多媒体播放。

我这里工程就是swing做的cs项目 
javafx是第三方的么? 可以嵌套到swing里么?
[其他解释]
该回复于2012-11-24 09:57:58被管理员删除
[其他解释]
引用:
引用:不使用swing,使用 javafx,自带多媒体播放。
我这里工程就是swing做的cs项目 
javafx是第三方的么? 可以嵌套到swing里么?


javafx2中的JFXPanel可以把JavaFX组件嵌入swing程序中。
[其他解释]
引用:
不一定非要使用jmf,只是建议:
http://blog.csdn.net/geminit2011/article/details/7682879
这是我写的,其中的NativeSwing中有一个vlc player可以实现播放mp4。
代码:Java code?1234567891011121314151617181920212223242526272829303……


大哥 我界面运行出来了 可以加载MP4视屏文件的时候
弹出这个提示框 求教如何解决  ‘我在网上试过的办法没能解决’ 还请指教
[其他解释]
引用:
引用:引用:不使用swing,使用 javafx,自带多媒体播放。
我这里工程就是swing做的cs项目 
javafx是第三方的么? 可以嵌套到swing里么?

javafx2中的JFXPanel可以把JavaFX组件嵌入swing程序中。

你好 请问有嵌入视屏的demo么 javafx以前没接触过 刚才看了下demo 里面加载的都是网络上的视屏 我加载本地视屏报错!! 还请指教
[其他解释]
引用:
什么错误?
new Media(mediafile.toURI())


 mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
这里的 MEDIA_URL 是网络视屏地址 但是我现在要加载的是本地视屏

如:private static final String MEDIA_URL = "C:\\DownLoad\\192.168.1.1681Time20121123090000Time20121123090010.mp4";

则:
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\DownLoad\192.168.1.1681Time20121123090000Time20121123090010.mp4
at java.net.URI$Parser.fail(URI.java:2810)
at java.net.URI$Parser.checkChars(URI.java:2983)
at java.net.URI$Parser.parse(URI.java:3020)
at java.net.URI.<init>(URI.java:577)
at javafx.scene.media.Media.<init>(Media.java:357)
... 9 more
[其他解释]
我把MP4文件放到src 下
则:
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null!
at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:232)
at javafx.scene.media.Media.<init>(Media.java:364)
at StreamingMediaPlayer.init(StreamingMediaPlayer.java:101)


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尚不在其支持的范围之内。
[其他解释]

引用:
你不看文档。Media的参数是一个URI格式的字符串。支持 http、file、jar协议。 http://............mp4
file:/.........mp4

上面那个写错了
 new Media("file:/D:/Temp/LaTeXDraw2.0.8/data/LaTeXDraw.avi")


你看下javafx的文档
Some of the features supported by the JavaFX media stack include the following:

    FLV container with MP3 and VP6

    MP3 audio

    MPEG-4 container with either AAC, H.264, or both

    HTTP, FILE protocol support

    Progressive download

    Seeking

    Buffer progress

    Playback functions (Play, Pause, Stop, Volume, Mute, Balance, Equalizer)

[其他解释]
引用:
引用:目前只支持flv,mp3和一些http的流媒体而已……mp4尚不在其支持的范围之内。


mp4本身在手机应用比较多,如果是桌面应用,可以考虑使用javafx+flv的形式,前提是你需要格式转换。
否则,只有寻找含有mp4解码器的java支持播放组件。
[其他解释]
引用:
目前只支持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 

热点排行