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文件皆可播放

解决方案 »

  1.   

    不一定非要使用jmf,只是建议:
    http://blog.csdn.net/geminit2011/article/details/7682879
    这是我写的,其中的NativeSwing中有一个vlc player可以实现播放mp4。
    代码:
    /*
     * Christopher Deckers ([email protected])
     * 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();
      }}附上截图:
      

  2.   

    import chrriis.common.UIUtils;
    import chrriis.dj.nativeswing.swtimpl.NativeInterface;
    import chrriis.dj.nativeswing.swtimpl.components.JVLCPlayer;
     JVLCPlayer
    这些类是哪个jar包里的 ?
      

  3.   

    你一定没看我的博文,你上网下载
    地址:http://djproject.sourceforge.net/ns/
      

  4.   

    下载不行就等会上我的资源去下载 我传上去了 估计要审批一会 叫swt jar包
      

  5.   

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

  6.   

    我这里工程就是swing做的cs项目 
    javafx是第三方的么? 可以嵌套到swing里么?
      

  7.   


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

  8.   

    你好 请问有嵌入视屏的demo么 javafx以前没接触过 刚才看了下demo 里面加载的都是网络上的视屏 我加载本地视屏报错!! 还请指教
      

  9.   

    什么错误?new Media(mediafile.toURI())
      

  10.   


     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
      

  11.   

    我把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
      

  12.   

    你不看文档。Media的参数是一个URI格式的字符串。支持 http、file、jar协议。
    http://............mp4
    file:/.........mp4上面那个写错了
     new Media("file:/D:/Temp/LaTeXDraw2.0.8/data/LaTeXDraw.avi") 
      

  13.   


    你看下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)
      

  14.   

    目前只支持flv,mp3和一些http的流媒体而已……mp4尚不在其支持的范围之内。
      

  15.   


    mp4本身在手机应用比较多,如果是桌面应用,可以考虑使用javafx+flv的形式,前提是你需要格式转换。
    否则,只有寻找含有mp4解码器的java支持播放组件。
      

  16.   

    oracle官网关于javafx支持media的代码demopackage 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);
    }
    }
      

  17.   

    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 || status == Status.HALTED) {
    // don't do anything in these states
    return;
    } if (status == Status.PAUSED || status == Status.READY
    || status == Status.STOPPED) {
    // rewind the movie if we're sitting at the end
    if (atEndOfMedia) {
    mp.seek(mp.getStartTime());
    atEndOfMedia = false;
    }
    mp.play();
    } else {
    mp.pause();
    }
    }
    });
    setBottom(mediaBar);

    mp.currentTimeProperty().addListener(
    new InvalidationListener() {
    public void invalidated(Observable ov) {
    updateValues();
    }
    }); mp.setOnPlaying(new Runnable() {
    public void run() {
    if (stopRequested) {
    mp.pause();
    stopRequested = false;
    } else {
    playButton.setText("||");
    }
    }
    }); mp.setOnPaused(new Runnable() {
    public void run() {
    System.out.println("onPaused");
    playButton.setText(">");
    }
    }); mp.setOnReady(new Runnable() {
    public void run() {
    duration = mp.getMedia().getDuration();
    updateValues();
    }
    }); mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);
    mp.setOnEndOfMedia(new Runnable() {
    public void run() {
    if (!repeat) {
    playButton.setText(">");
    stopRequested = true;
    atEndOfMedia = true;
    }
    }
    }); // Add spacer
    Label spacer = new Label("   ");
    mediaBar.getChildren().add(spacer); // Add Time label
    Label timeLabel = new Label("Time: ");
    mediaBar.getChildren().add(timeLabel); // Add time slider
    timeSlider = new Slider();
    HBox.setHgrow(timeSlider, Priority.ALWAYS);
    timeSlider.setMinWidth(50);
    timeSlider.setMaxWidth(Double.MAX_VALUE);
    timeSlider.valueProperty().addListener(new InvalidationListener() {
    public void invalidated(Observable ov) {
    if (timeSlider.isValueChanging()) {
    // multiply duration by percentage calculated by slider
    // position
    mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
    }
    }
    });
    mediaBar.getChildren().add(timeSlider); // Add Play label
    playTime = new Label();
    playTime.setPrefWidth(130);
    playTime.setMinWidth(50);
    mediaBar.getChildren().add(playTime); // Add the volume label
    Label volumeLabel = new Label("Vol: ");
    mediaBar.getChildren().add(volumeLabel); // Add Volume slider
    volumeSlider = new Slider();
    volumeSlider.setPrefWidth(70);
    volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
    volumeSlider.setMinWidth(30);
    volumeSlider.valueProperty().addListener(new InvalidationListener() {
    public void invalidated(Observable ov) {
    if (volumeSlider.isValueChanging()) {
    mp.setVolume(volumeSlider.getValue() / 100.0);
    }
    }
    });
    mediaBar.getChildren().add(volumeSlider);
    } protected void updateValues() {
    if (playTime != null && timeSlider != null && volumeSlider != null) {
    Platform.runLater(new Runnable() {
    public void run() {
    Duration currentTime = mp.getCurrentTime();
    playTime.setText(formatTime(currentTime, duration));
    timeSlider.setDisable(duration.isUnknown());
    if (!timeSlider.isDisabled()
    && duration.greaterThan(Duration.ZERO)
    && !timeSlider.isValueChanging()) {
    timeSlider.setValue(currentTime.divide(duration)
    .toMillis() * 100.0);
    }
    if (!volumeSlider.isValueChanging()) {
    volumeSlider.setValue((int) Math.round(mp.getVolume() * 100));
    }
    }
    });
    }
    } private static String formatTime(Duration elapsed, Duration duration) {
    int intElapsed = (int) Math.floor(elapsed.toSeconds());
    int elapsedHours = intElapsed / (60 * 60);
    if (elapsedHours > 0) {
    intElapsed -= elapsedHours * 60 * 60;
    }
    int elapsedMinutes = intElapsed / 60;
    int elapsedSeconds = intElapsed - elapsedHours * 60 * 60
    - elapsedMinutes * 60; if (duration.greaterThan(Duration.ZERO)) {
    int intDuration = (int) Math.floor(duration.toSeconds());
    int durationHours = intDuration / (60 * 60);
    if (durationHours > 0) {
    intDuration -= durationHours * 60 * 60;
    }
    int durationMinutes = intDuration / 60;
    int durationSeconds = intDuration - durationHours * 60 * 60
    - durationMinutes * 60;
    if (durationHours > 0) {
    return String.format("%d:%02d:%02d/%d:%02d:%02d", elapsedHours,
    elapsedMinutes, elapsedSeconds, durationHours,
    durationMinutes, durationSeconds);
    } else {
    return String.format("%02d:%02d/%02d:%02d", elapsedMinutes,
    elapsedSeconds, durationMinutes, durationSeconds);
    }
    } else {
    if (elapsedHours > 0) {
    return String.format("%d:%02d:%02d", elapsedHours,
    elapsedMinutes, elapsedSeconds);
    } else {
    return String.format("%02d:%02d", elapsedMinutes,
    elapsedSeconds);
    }
    }
    }
    }