In previous articles i showed you that JAVA having broad working areas. Today i will show you how to play videos in JAVA using javafx api.
For playing videos in JAVA we need following things :
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import java.io.*;
public class video extends Application{
private Media media;
private MediaPlayer player;
private MediaView view;
private Scene scene;
private Group root;
public void start(Stage stage) throws Exception {
root = new Group();
root.setAutoSizeChildren(true);
scene = new Scene(root,800,600);
media = new Media(new File("/media/amar/Disk 3/my softwares/dhoom3.mp4")
.toURI().toString());
player = new MediaPlayer(media);
player.play();
view = new MediaView(player);
view.fitHeightProperty().bind(scene.heightProperty());
view.fitWidthProperty().bind(scene.widthProperty());
root.getChildren().add(view);
root.getChildren().add(vol);
stage = new Stage();
stage.setScene(scene);
stage.show();
}
}
After it save the program and run as JAVA application. You will see the video is playing normally. The drawback of media player in JAVA that it is unable to support all video formats.
Good Luck guys.
For playing videos in JAVA we need following things :
- JAVA 7 JDK or greater
- JAVAFX SDK
- Eclipse or Netbeans IDE
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import java.io.*;
public class video extends Application{
private Media media;
private MediaPlayer player;
private MediaView view;
private Scene scene;
private Group root;
public void start(Stage stage) throws Exception {
root = new Group();
root.setAutoSizeChildren(true);
scene = new Scene(root,800,600);
media = new Media(new File("/media/amar/Disk 3/my softwares/dhoom3.mp4")
.toURI().toString());
player = new MediaPlayer(media);
player.play();
view = new MediaView(player);
view.fitHeightProperty().bind(scene.heightProperty());
view.fitWidthProperty().bind(scene.widthProperty());
root.getChildren().add(view);
root.getChildren().add(vol);
stage = new Stage();
stage.setScene(scene);
stage.show();
}
}
After it save the program and run as JAVA application. You will see the video is playing normally. The drawback of media player in JAVA that it is unable to support all video formats.
Good Luck guys.