Java Reference
In-Depth Information
def playCtrl = e.source as ImageView;
if(player.status == player.PLAYING){
playCtrl.image =
When the variable controls is added to a scene object and the application is executed, it
produces the screen shown in the following screenshot:
How it works...
The Media API is comprised of several components which, when put together, provides the
mechanism to stream and playback the audio source. To playback audio requires two classes,
including Media and MediaPlayer . Let's take a look at how these classes are used to
playback audio in the previous example.
F The MediaPlayer —the first significant item in the code is the declaration and
initialization of a MediaPlayer instance assigned to the variable player . To load
the audio file, we assign an instance of Media to . The Media class
is used to specify the location of the audio. In our example, it is a URL that points to
an MP3 file.
F The controls —the play, pause, and stop buttons are grouped in the Group object
called controls . They are made of three separate image files: play-large.
png , pause-large.png , and stop-large.png, loaded by two instances of the
ImageView class. The ImageView objects serve to display the control icons and to
control the playback of the audio:
When the application starts, imgView displays image play-
large.png . When the user clicks on the image, it invokes its
action-handler function, which firsts detects the status of the
MediaPlayer instance. If it is not playing, it starts playback of the
Search WWH ::

Custom Search