Java Reference
In-Depth Information
Figure 9-11.
The
MediaView
s slide apart to reveal the hidden message
Converting AudioPlayer into a VideoPlayer
Based on what you have learned so far, you might think that converting the AudioPlayer application to play video
is a straightforward task, and you would be right. The first step is simply to rename the
SongModel
class to the more
appropriate
MediaModel
. No code changes are required. Although movies do not typically contain metadata, it does
not hurt to leave in the code that looks for them. Rather than display metadata, we create a new view that displays the
MediaView
instead. This
VideoView
class is shown in Listing 9-36.
Listing 9-36.
A View That Displays the
MediaView
Node
public class VideoView extends AbstractView {
public VideoView(MediaModel mediaModel) {
super(mediaModel);
}
@Override
protected Node initView() {
MediaView mv = new MediaView();
mv.mediaPlayerProperty().bind(mediaModel.mediaPlayerProperty());
return mv;
}
}
This simple class uses its
initView
method to create a
MediaView
and bind the
MediaView
's
mediaPlayerProperty
to the
mediaPlayerProperty
we created in our
MediaModel
(formerly
SongModel
) class.
Search WWH ::
Custom Search