https://docs.oracle.com/javafx/2/media/simpleplayer.htm
2 Embedding Media Into a Web Page
In this section, you'll explore how to add animated media 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 that is shown in Figure 2-1.
Figure 2-1 Structure of the Embedded Media Player
Description of "Figure 2-1 Structure of the Embedded Media Player"
To Get Started
You can build a JavaFX application using any development tool designed for creating a Java application. The tool used in this document is the NetBeans IDE. Do the following steps before continuing to build this document's sample application that uses the JavaFX Media features:
-
Use the
JavaFX Release Documentation
page to find the System Requirements document that you need to verify that your system meets the minimum requirements, including the version of NetBeans IDE. -
Use the Installation Guide on the
JavaFX Release Documentation
page to get the information on how to install the version of JavaFX SDK software you plan to use. -
Install the required NetBeans IDE using the NetBeans information provided in the JavaFX System Requirements documents available from the
JavaFX Release Documentation
page. -
If necessary, get acquainted with the following documents to get familiar with JavaFX:
Create the Application
-
From the NetBeans IDE, set up your JavaFX project as follows:
-
From the File menu, choose New Project.
-
In the JavaFX application category, choose JavaFX Application. Click Next.
-
Name the project
EmbeddedMediaPlayer
and ensure the Create Application Class field has the value ofembeddedmediaplayer.EmbeddedMediaPlayer
. Click Finish.
-
-
Copy the
import
statements in Example 2-1 and paste them in theEmbeddedMediaPlayer.java
file, replacing all of theimport
statements that were automatically generated by the NetBeans IDE.Example 2-1 Replace Default Import Statements
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; import javafx.stage.Stage;
For now, ignore the warnings on the margin since the lines of code that use the Media classes will be added in the next few steps.
-
Specify the media file source to be used and the String variable by adding the lines in bold inExample 2-2. For this example, use the animated video located at
download.oracle.com
or specify your own file. Add the lines after thepublic class EmbeddedMediaPlayer
line. -
Modify the
start
method so that it looks like Example 2-3. This is will create an empty scene with a group root node and dimension of 540 wide by 210 height. -
Now, define the Media and the MediaPlayer objects by adding the code in Example 2-4 before the
primaryStage.setScene(scene)
line. Set theautoPlay
variable totrue
so that the video can start immediately. -
Define the MediaView object and add the media player to the Node-based viewer by copying the comment and two lines of code in Example 2-5 and pasting it right after the
mediaPlayer.setAutoPlay(true)
line. -
Right-click on any whitespace and select Format to fix the line formatting after adding the lines of code.
-
Right-click the EmbeddedMediaPlayer project node in the Projects pane and select Clean and Build.
-
After a successful build, run your application by right-clicking the project node and selecting Run.
Note:
If you are using the media file source used in this tutorial and you are running the application behind a firewall, you might need to set the application's proxy in order for the application to be able to access the media source file. Right-click the EmbeddedMediaPlayer project node in the Project window, select Properties, and in the Project Properties dialog, select Run. Set the VM Options field with something similar to
-Dhttp.proxyHost=
yourproxyhost.com-Dhttp.proxyPort=
somePort#, where yourproxyhost.com is your company's proxy server and somePort# is a port number you are assigned to use.
-
Deploy the sample application you just built to a browser by embedding it into your HTML content using the instructions in the
Deployment in the Browser
document. Copy the code from the EmbeddedMediaPlayer.html file that was automatically generated by the IDE to the target web page.
'프로그래밍 > JAVAFX' 카테고리의 다른 글
3 Controlling Media Playback (0) | 2015.03.04 |
---|---|
1 Introduction to JavaFX Media (0) | 2015.03.04 |