user2748943
user2748943

Reputation: 563

Play mp4 clip inside an existing GUI

I'm trying to play a short .mp4 animation from my local machine. I've installed Javafx to try and help me with this, but I'm completely unfamiliar with how to use it, since my only experience is with swing. I've successfully got a video to play with online sources (using help from Play a video using javafx). I assume this only works with an online clip as a .flv file instead of mp4. Anyway the code I have is

package application;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.media.*;
import javafx.stage.Stage;

public class VideoPlayerExample extends Application {
  public static void main(String[] args) throws Exception { launch(args); }
  @Override public void start(final Stage stage) throws Exception {
    final MediaPlayer oracleVid = new MediaPlayer(
      new Media("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv")
    );
    stage.setScene(new Scene(new Group(new MediaView(oracleVid)), 540, 208));
    stage.show();

    oracleVid.play();
  }
}

I'm trying to see if there's a simple way I can replace the url when creating oracleVid with my own .mp4 file with a build path from my local machine? Is what I have here completely opposite from what I'm looking for?

Upvotes: 0

Views: 239

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168835

I'm trying to see if there's a simple way I can replace the url when creating oracleVid with my own .mp4 file with a build path from my local machine?

Use file.toURI().toURL()..

Upvotes: 1

Related Questions