samedi 17 juin 2017

Java JavaFX play Video asynchronously from superclass

I'm new to Java and trying to build a Server for my Raspberry that plays a Video when some special message is received.

In my "Main" class I have an instance of my Socket server class, that is listening and calling a Method in its superclass (Main) if message received. Then my "Main" class is calling the "play" method in my "Mediaplayer" class, that look like this:

public class VidPlayer extends Application implements Runnable{

private Group root;
private URL workdir;
private Media media;
private MediaPlayer mp;
private MediaView view;
private Scene scene;

public VidPlayer(){
}
public void setup(){

    String[] empty = new String[0];
    launch(empty);
}
public void play(){
    mp.play();
}

@Override
public void start(Stage primaryStage) throws Exception {

    root = new Group();

    workdir = getClass().getResource("IMG_0237B.m4v");
    File f = new File (workdir.getPath());

    media = new Media(f.toURI().toString());
    mp = new MediaPlayer(media);
    view = new MediaView(mp);

    root.getChildren().add(view);
    scene = new Scene(root, 400 , 400, Color.AZURE);

    primaryStage.setScene(scene);
    primaryStage.show();



}

@Override
public void run() {
    setup();

}
}

of course it doesn't work, probably this is complete rubbish.. calling play() caused NullPointerException.. how can I access my JavaFx objects asynchronously from sibling classes? The examples I found on the net were all written in complete blocking style..

thanks for having a look

Aucun commentaire:

Enregistrer un commentaire