Embedding Media Into the Web Page
Explore how to add animated cartoon content to your web page by creating a simple media panel. To create a media player you need to implement the structure of the three nested objects shown in the following figure.
Figure 1: Structure of the Embedded Player
- Define the
Mediaobject and specify the source file to play. For this example, use the Big Buck Bunny animated cartoon located atsun.edgeboss.netor specify your own file.
var media = Media {
source: "http://sun.edgeboss.net/download/sun/media/1460825906/1460825906_2956241001_big-buck-bunny-640x360.flv"
}
- Create a
MediaPlayerobject by specifying the media. Set theautoPlayvariable totrueso that the cartoon can start immediately.
var mediaPlayer = MediaPlayer {
autoPlay: true
media: media
}
- Add the media player to the Node-based viewer, specifying the width and the height of the media panel.
var mediaView = MediaView {
fitWidth: 200
fitHeight: 100
mediaPlayer: mediaPlayer
}
- Add the media viewer to the scene's content.
Stage {
title: "Embedded Player"
width: 200
height: 100
scene: Scene {
content: mediaView
}
}
- Compile and run your application. Remember to add all the required import statements to your code. Find the complete application code in
EmbeddedPlayer.fx - Deploy the sample by using the Run in Browser Execution Model.
- After the media player is built and deployed, you can embed it into your HTML content. Copy the following code from the
MediaSamples.htmlfile automatically generated by the IDE to the target web page.
<script src="http://dl.javafx.com/dtfx.js"></script>
<script>
javafx(
{
archive: "MediaSamples.jar",
draggable: true,
width: 200,
height: 100,
code: "mediasamples.EmbeddedPlayer",
name: "MediaSamples"
}
);
</script>
The following is a typical use case of an embedded media panel. It shows a movie thumbnail accompanied by some production details.
In order to play the media content used in this application, ensure that the required codecs are installed in your system.
|
Title: Big Buck Bunny Plot: A good-natured rabbit, "Big Buck," finds his day spoiled by the rude behavior of forest bullies. Duration: 9.56 |
Sandeep Konchady
Staff Engineer, Oracle Corporation
Alla Redko
Technical Writer, Sun Microsystems