Java Reference
In-Depth Information
Getting ready
This recipe uses classes from the Media API located in the package.
As mentioned in the introduction of this recipe, the example presented here extends the code
from the previous recipe to transform the audio player to now play video. We are going to
reuse the same icons and the same logic to control the playback of the video. To review how
to configure and use the Media API for playback, review the previous recipe Playing audio
with MediaPlayer .
To illustrate video playback, the application plays back the award-winning, open-sourced,
short, animated movie Big Buck Bunny . By default, the recipe will play the 854 x 480
H.264 version found at the address
bigbuckbunny_movies/ .
How to do it...
Similar to audio, playing video is simple. The abbreviated code given next highlights the
portion of the code that is changed to be able to display video. You can see the full listing
of the code at ch05/source-code/src/media/VideoPlayerDemo.fx .
def w = 800;
def h = 600;
def maxW = w * 0.8;
def maxH = h * 0.7;
var scene:Scene;
def mediaSource =
def player = MediaView {
layoutX:(w - maxW)/2 layoutY:(h-maxH)/2
mediaPlayer: MediaPlayer {media: Media {source: mediaSource }}
fitWidth:maxW fitHeight:maxH
def controls = Group {
fraction:0.4 bottomOpacity:0.1 topOffset:3}
HBox{spacing:10 content:[
ImageView {id:"playCtrl"
def playCtrl = e.source as ImageView;
Search WWH ::

Custom Search