Grabbing the media file time using setOnReady randomly stops executing

am trying to get the time of a mp4 mediafile with a file chooser, and also the url, and put them on 2 different textfields(using FXML), the url part works fine, but I am having a problem with the time.

Here is the code I have for getting the time.

private void setTimeField(File selectedFile)

{

Media mediaFile = new Media(selectedFile.toURI().toString());

MediaPlayer mediaPlayer = new MediaPlayer(mediaFile);

mediaPlayer.setOnReady(new Runnable()

{

@Override

public void run()

{

int timeOfVid = (int) mediaFile.getDuration().toSeconds();

txtTime.setText(model.getTimeInString(timeOfVid));

}

}

);

}

The problem is that sometimes it does set the txtTime, and other times it doesnt, and it feels very random about doing...

Read More »

By: StackOverFlow - Wednesday, 9 January

Related Posts