Java Reference
In-Depth Information
In this example we will use a JavaFX podcast from Oracle Technology Network TechCast series
where
Nandini Ramani
discusses JavaFX. The stream can be found at
http://streaming.
oracle.com/ebn/podcasts/media/8576726_Nandini_Ramani_030210.mp3
.
How to do it...
The code given next has been shortened to illustrate the essential portions involved in loading
and playing an audio stream. You can get the full listing of the code in this recipe from
ch05/
source-code/src/media/AudioPlayerDemo.fx
def w = 400;
def h = 200;
var scene:Scene;
def
mediaSource
= "http://streaming.oracle.com/ebn/podcasts/media/
8576726_Nandini_Ramani_030210.mp3";
def
player = MediaPlayer
{media:
Media
{source:
mediaSource
}}
def
controls
=
Group
{
layoutX:(w-110)/2
layoutY:(h-50)/2
effect:Reflection{
fraction:0.4 bottomOpacity:0.1 topOffset:3
}
content:[
HBox{spacing:10 content:[
ImageView
{id:"playCtrl"
image
:Image{url:"{__DIR__}
play-large.png
"}
onMouseClicked:function(e:MouseEvent){
def
playCtrl
=
e.source as ImageView
;
if(not(player.
status
== player.PLAYING)){
playCtrl.
image
=
Image
{url:"{__DIR__}
pause-large.png
"}
player.play();
}else if(player.
status
== player.PLAYING){
playCtrl.
image
=
Image
{url:"{__DIR__}play-large.png"}
player.pause();
}
}
}
ImageView
{id:"stopCtrl"
image
:Image{url:"{__DIR__}
stop-large.png
"}
onMouseClicked:function(e){