title: How to run a javaFX MediaPlayer in swing?
body: <p>I've made a simple Media Player for an application I'm working on, the problem is that I thought that you could simply integrate JavaFX into Swing. Which is not the case. I have been searching for a solution to this problem and tried to use this website: <a href="http://docs.oracle.com/javafx/2/swing/jfxpub-swing.htm" rel="nofollow">http://docs.oracle.com/javafx/2/swing/jfxpub-swing.htm</a> 
  The problem is that even though I have the website that explains how to put the code together, I still don't understand how. Here is the mediaplayer and I plan to integrate it into my Swing code, so that I can call the media player when a button is clicked. Here is all my code for the media player and if anyone can share some light on how to integrate it into my Swing code i.e my GUI, I would probably have to kiss you through the computer. </p>
  
  <p><code></p>
  
  <pre>public class Player extends Application{
  
  private boolean atEndOfMedia = false;
  private final boolean repeat = false;
  private boolean stopRequested = false;
  private Duration duration;
  private Label playTime;
  private Slider volumeSlider;
  
  @Override
  public void start(final Stage stage) throws Exception {
  
      stage.setTitle("Movie Player");//set title
      Group root = new Group();//Group for buttons etc
  
      final Media media = new Media("file:///Users/Paul/Downloads/InBruges.mp4");
      final MediaPlayer playa = new MediaPlayer(media);
      MediaView view = new MediaView(playa);
  
      //Slide in and out and what causes that.
      final Timeline slideIn = new Timeline();
      final Timeline slideOut = new Timeline();
      root.setOnMouseEntered(new javafx.event.EventHandler&lt;javafx.scene.input.MouseEvent&gt;()              { 
          @Override
          public void handle(MouseEvent t) {
              slideIn.play();
          }
      });
  
      root.setOnMouseExited(new javafx.event.EventHandler&lt;javafx.scene.input.MouseEvent&gt;() {
          @Override
          public void handle(MouseEvent t) {
              slideOut.play();
          }
      });
  
      final VBox vbox = new VBox();
      final Slider slider = new Slider();
      final Button playButton  = new Button("|&gt;");
  
      root.getChildren().add(view);
      root.getChildren().add(vbox);
      vbox.getChildren().add(slider);
      vbox.getChildren().add(playButton);
      vbox.setAlignment(Pos.CENTER);
  
      Scene scene = new Scene(root, 400, 400, Color.BLACK);
      stage.setScene(scene);
      stage.show();
  
      // Play/Pause Button
     playButton.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
          @Override
      public void handle(ActionEvent e) {
      Status status = playa.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) {
              playa.seek(playa.getStartTime());
              atEndOfMedia = false;
           }
           playa.play();
           } else {
             playa.pause();
           }
       }
   });
  
     //Listeners and Shit for Play Button
      playa.setOnPlaying(new Runnable() {
          @Override
          public void run() {
              if (stopRequested) {
                  playa.pause();
                  stopRequested = false;
              } else {
                  playButton.setText("||");
              }
          }
      });
  
      playa.setOnPaused(new Runnable() {
          @Override
          public void run() {
              playButton.setText("&gt;");
          }
      });
  
      playa.play();
      playa.setOnReady(new Runnable() {
  
          @Override    
          public void run(){
          int v = playa.getMedia().getWidth();
          int h = playa.getMedia().getHeight();
  
          stage.setMinWidth(v);
          stage.setMinHeight(h);
  
          vbox.setMinSize(v, 100);
          vbox.setTranslateY(h-50);
  
          //slider and graphical slide in/out
          slider.setMin(0.0);
          slider.setValue(0.0);
          slider.setMax(playa.getTotalDuration().toSeconds());
  
          slideOut.getKeyFrames().addAll(
                  new KeyFrame(new Duration(0),
                        new KeyValue(vbox.translateYProperty(), h-100),
                        new KeyValue(vbox.opacityProperty(), 0.9)
                              ),
                  new KeyFrame(new Duration(300),
                        new KeyValue(vbox.translateYProperty(), h),
                        new KeyValue(vbox.opacityProperty(), 0.0)
            )
            );
          slideIn.getKeyFrames().addAll(
                  new KeyFrame(new Duration(0),
                      new KeyValue(vbox.translateYProperty(), h),
                      new KeyValue(vbox.opacityProperty(), 0.0) 
                              ),
                  new KeyFrame(new Duration(300),
                          new KeyValue(vbox.translateYProperty(), h-100),
                          new KeyValue(vbox.opacityProperty(), 0.9)
            )
            );
      }
  
  });
  
      //Slider being current and ability to click on slider. 
  playa.currentTimeProperty().addListener(new ChangeListener&lt;Duration&gt;(){
      @Override
      public void changed(ObservableValue&lt;? extends Duration&gt; observableValue, Duration   duration, Duration current){
         slider.setValue(current.toSeconds());
     }
    });
     slider.setOnMouseClicked(new javafx.event.EventHandler&lt;javafx.scene.input.MouseEvent&gt;()   {
  
          @Override
          public void handle(javafx.scene.input.MouseEvent t) {
              playa.seek(Duration.seconds(slider.getValue()));
          }
  });
  }
  </code></pre>