Java Reference
In-Depth Information
new
EmbeddedMediaPlayerComponent
();
setLayout
(
new
new
new
BorderLayout
());
add
(
videoCanvas
,
BorderLayout
.
CENTER
);
player
=
videoCanvas
.
getMediaPlayer
();
}
public
public
void
void
play
(
String media
) {
player
.
prepareMedia
(
media
);
player
.
parseMedia
();
player
.
play
();
}
}
}
JavaFX
JavaFX is integrated with most Java 7 JDKs and hopefully all Java 8 ones, or you can down-
load it separately from Oracle. The code in
Example 12-9
shows a simple JavaFX media
player. We construct a Media clip with a
test video
from
MediaCollege.com
, create a player,
and call
play()
; we also have to set up the view window.
Example 12-9. JfxVideo.java
public
public class
class
JfxVideo
JfxVideo
extends
extends
Application
{
public
public static
void
main
(
String
[]
args
) {
launch
(
args
);
static
void
}
@Override
public
public
void
throws
Exception
{
primaryStage
.
setTitle
(
"JavaFX Video"
);
final
void
start
(
Stage primaryStage
)
throws
final
List
<
String
>
args
=
getParameters
().
getRaw
();
String url
=
args
.
size
() >
0
?
args
.
get
(
args
.
size
() -
1
) :
"http://www.mediacollege.com/"
+
"video-gallery/testclips/20051210-w50s.flv"
;
Media media
=
new
new
Media
(
url
);
MediaPlayer player
=
new
new
MediaPlayer
(
media
);
player
.
play
();
MediaView view
=
new
new
MediaView
(
player
);
Group root
=
new
new
Group
();
root
.
getChildren
().
add
(
view
);