JavaFX - How can i start a 24 hour video (using javafx media) at the exact current time from the computer system clock?

94matheus :

I have a 24hour recording starting at 00:00 hour and ending 24 hours latter. I want to run the program and have it play the video starting at the same time that it is showing on the system clock. For example, it is 20:14 here in Brazil now, so if i execute the program, the video would start playing at the 20hours and 14mins mark.

Basically, i want to sync up the video time with the actual time displayed on the system clock.

My code is kind of messy because the assigment requires the use of Processing ide but for me to actually do what I intend to I'm trying to use Eclipse importing PApplet and all that. Anyway, I just looked up how to play a video using javafx and even though my video is huge it can start playing it instantly.

public class UsingProcessing extends PApplet{

  String Dir = System.getProperty("C:");
  Stage stage;

  public static void main(String[] args)  {

      PApplet.main("UsingProcessing");
  }

  public void settings(){

      size(1100, 618,FX2D);
  }

  public void setup(){

      try {

          Field field = PSurfaceFX.class.getDeclaredField("stage");
          field.setAccessible(true);
          stage = (Stage)field.get(surface);

          File f = new File(Dir, "narrativas.mp4");

          Media media = new Media(f.toURI().toURL().toString());
          javafx.scene.media.MediaPlayer player = new 
          javafx.scene.media.MediaPlayer(media);
          MediaView viewer = new MediaView(player);

          DoubleProperty width = viewer.fitWidthProperty();
          DoubleProperty height = viewer.fitHeightProperty();
          width.bind(Bindings.selectDouble(viewer.sceneProperty(), "width"));
          height.bind(Bindings.selectDouble(viewer.sceneProperty(), "height"));
          viewer.setPreserveRatio(true);

          StackPane root = new StackPane();
          root.getChildren().add(viewer);


          Scene scenes = new Scene(root, 1100, 618, Color.BLACK);
          stage.setScene(scenes);
          stage.setTitle("OBSV.CamFeed.6°07'08.3\"S 12°23'51.5\"E");
          stage.setFullScreen(false);
          stage.show();
          player.play();
      } 

      catch (Exception e) {

          e.printStackTrace();
      }
  }
}

I'm basically using the standard way of playing a video with javafx in Eclipse.

Alex Broadwin :

First you need to get the duration since midnight:

ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime startOfDay = now.toLocalDate().atStartOfDay();
java.time.Duration d = java.time.Duration.between(startOfDay, now);

Convert that java.time.Duration object to a javafx.util.Duration object.

javafx.util.Duration duration = new javafx.util.Duration( d.toMillis() ) ;

Then call MediaPlayer::setStartTime.

player.setStartTime(duration);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=80896&siteId=1