Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8127074

MediaPlayer or Media updating properties on wrong thread.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • fx2.1
    • fx2.1
    • javafx
    • Mac

      I have a label which I want to bind up to the current time and total time for playing media like this:

      Label timeLabel = new Label();
      Media media = new Media(....):
      MediaPlayer mediaPlayer = new MediaPlayer(media);
      mediaPlayer.setAutoPlay(true);

      timeLabel.textProperty().bind(Bindings.concat("Time: ",mediaPlayer.currentTimeProperty()," Total: ", media.durationProperty()));

      This should work but either mediaPlayer.currentTimeProperty or media.durationProperty is not being set on the FX thread so I get a Exception:

      Exception in thread "Timer-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-0
      at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:218)
      at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:360)
      at javafx.scene.Parent$1.onProposedChange(Parent.java:224)
      at com.sun.javafx.collections.VetoableObservableList.setAll(VetoableObservableList.java:70)
      at com.sun.javafx.collections.ObservableListWrapper.setAll(ObservableListWrapper.java:232)
      at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:544)
      at com.sun.javafx.scene.control.skin.LabeledSkinBase.handleControlPropertyChanged(LabeledSkinBase.java:208)
      at com.sun.javafx.scene.control.skin.SkinBase$4.changed(SkinBase.java:263)
      at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:67)
      at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:64)
      at javafx.beans.property.StringPropertyBase.fireValueChangedEvent(StringPropertyBase.java:80)
      at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:87)
      at javafx.beans.property.StringPropertyBase.access$100(StringPropertyBase.java:26)

            bpb Brian Burkhalter
            jasper Jasper Potts (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: