Skip to main content

MediaPlayer and current time

1 reply [Last post]
zandig
Offline
Joined: 2006-10-16
Points: 0

Is there a way for one to retrieve the current time of a Media object, say an mp3, while it is being played by MediaPlayer? For example, let's say I would like to display the time of a song while it is playing... so that the display would start at 0:00 and continue increasing until the end of the song. I couldn't find something in the javafx.scene.media.MediaPlayer API to retrieve this value. I believe I saw something to use to set the current time, which is the field MediaPlayer.currentTime field, but I didn't see how I could retrieve the current time so that I could bind to it and display it as it changes. Any ideas?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
coffeejolts
Offline
Joined: 2007-05-17
Points: 0

According to the documentation, you should be able to use MediaPlayer.currentTime to get the current time, as well as set it. You should be able to bind a label to the value in order to get the time readout, or bind a slider so that you can jump to a different point in the clip by dragging the slider.

http://openjfx.java.sun.com/hudson/job/openjfx-compiler-technology-previ...