package javafx_media;
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;
/**
*
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_VideoPlayer extends Application {
private static final String MEDIA_URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";
private static String arg1;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("java-buddy.blogspot.com/");
Group root = new Group();
Scene scene = new Scene(root, 540, 210);
// create media player
Media media = new Media((arg1 != null) ? arg1 : 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);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Actually, it's a example preovided from Oracle JavaFX 2.0 Doc here.
Related:
- Embed JavaFX inside Swing JFrame
hi really god example, ihave a question. how can i call this player from a jframe o jpanel?
ReplyDeleteplease read Embed JavaFX inside Swing JFrame.
Deletereally thanks sorry for the late in the response
ReplyDeleteHey, everytime I try to run your example, I've got a black scene.
ReplyDeleteThe MediaPlayer.Status is still "UNKNOWN".
Any clues what i've might done wrong?
Have you installed your lib format ? if not, please install it
Deletedirac-libs-1.0.2-9.fc18.i686.rpm
libavcodec52-0.7.15-32.fc18.i686.rpm
libavformat52-0.7.15-32.fc18.i686.rpm
libavutil50-0.7.15-32.fc18.i686.rpm
libxavs1-0.1.51-2.fc18.i686.rpm
Once installed, javafx plays music like a charm.