X

Geertjan's Blog

  • May 22, 2015

javafx.scene.media.MediaPlayer in the NetBeans Platform

Geertjan Wielenga
Product Manager

Let's integrate javafx.scene.media.MediaPlayer in a NetBeans Platform application so that you can, for example, have an interesting TopComponent like the below.

Steps:

  1. Copy this class into a NetBeans module.

  2. In your TopComponent, which here is named 'NBMediaPlayerTopComponent':
    public NBMediaPlayerTopComponent() {
    initComponents();
    setName(Bundle.CTL_NBMediaPlayerTopComponent());
    setToolTipText(Bundle.HINT_NBMediaPlayerTopComponent());
    setLayout(new BorderLayout());
    JPanel playerpanel = new JPanel();
    final JFXPanel jFXPanel = new JFXPanel();
    playerpanel.add(jFXPanel);
    add(playerpanel, BorderLayout.CENTER);
    Platform.setImplicitExit(false);
    Platform.runLater(new Runnable() {
    @Override
    public void run() {
    initFxLater(jFXPanel);
    }
    });
    }
    private static void initFxLater(JFXPanel panel) {
    MediaPlayer mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
    mediaPlayer.setAutoPlay(true);
    mediaPlayer.setVolume(20.0);
    panel.setScene(new Scene(new MediaControl(mediaPlayer)));
    }

References:

http://docs.oracle.com/javafx/2/swing/MediaControl.java.htm

http://stackoverflow.com/questions/22364461/swing-and-javafx

http://stackoverflow.com/questions/15479821/javafx-mediaplayer-volume-trouble-why-the-volume-of-mediaplayer-do-not-chang

https://platform.netbeans.org/tutorials/nbm-javafx.html

Join the discussion

Comments ( 1 )
  • guest Tuesday, June 9, 2015

    It's there a simple way to open media files with this player?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.