Java Reference
In-Depth Information
Creating a media playback component
The previous two recipes, Playing audio with MediaPlayer and Playing video with MediaView ,
show you how to build applications quickly to playback media sources with basic controls,
such as play, pause, and stop. However, the Media API supports more functionalities than
what have been discussed so far. This recipe shows you how to build a custom media
component to playback media sources providing extended functionalities such as fast
forward, reverse, and timing information.
Getting ready
This recipe uses classes from the Media API located in the javafx.scene.media package.
The example presented here extends the code from the previous recipe Playing video with
MediaView to create a playback component . The component will take advantage of the
functionalities and runtime data provided by the Media API to extend the features of the video
player example. Before you continue, ensure that you are familiar with the materials covered
in the recipes Playing audio with MediaPlayer and Playing video with MediaView .
How to do it...
The shortened code given next provides highlights of the more significant items involved in
creating the playback component. You can access the full listing of the code from ch05/
source-code/src/media/MediaControllerComponent.fx .
1. Let's define class MediaController as CustomNode that encapsulates the
playback icons/buttons and control logic:
class MediaController extends CustomNode {
public var mediaPlayer:MediaPlayer;
var timestat = bind
"{%02d mediaPlayer.currentTime.toHours()
mod 12 as Integer}:"
"{%02d mediaPlayer.currentTime.toMinutes()
mod 60 as Integer}:"
"{%02d mediaPlayer.currentTime.toSeconds()
mod 60 as Integer}/"
"{%02d mediaPlayer.media.duration.toHours()
mod 12 as Integer}:"
"{%02d mediaPlayer.media.duration.toMinutes()
mod 60 as Integer}:"
"{%02d mediaPlayer.media.duration.toSeconds()
mod 60 as Integer}";
 
Search WWH ::




Custom Search