- JavaFX Tutorial
- JavaFX - Home
- JavaFX - Overview
- JavaFX Installation and Architecture
- JavaFX - Environment
- JavaFX - Installation Using Netbeans
- JavaFX - Installation Using Eclipse
- JavaFX - Installation using Visual Studio Code
- JavaFX - Architecture
- JavaFX - Application
- JavaFX 2D Shapes
- JavaFX - 2D Shapes
- JavaFX - Drawing a Line
- JavaFX - Drawing a Rectangle
- JavaFX - Drawing a Rounded Rectangle
- JavaFX - Drawing a Circle
- JavaFX - Drawing an Ellipse
- JavaFX - Drawing a Polygon
- JavaFX - Drawing a Polyline
- JavaFX - Drawing a Cubic Curve
- JavaFX - Drawing a Quad Curve
- JavaFX - Drawing an Arc
- JavaFX - Drawing an SVGPath
- JavaFX Properties of 2D Objects
- JavaFX - Stroke Type Property
- JavaFX - Stroke Width Property
- JavaFX - Stroke Fill Property
- JavaFX - Stroke Property
- JavaFX - Stroke Line Join Property
- JavaFX - Stroke Miter Limit Property
- JavaFX - Stroke Line Cap Property
- JavaFX - Smooth Property
- Operations on 2D Objects
- JavaFX - 2D Shapes Operations
- JavaFX - Union Operation
- JavaFX - Intersection Operation
- JavaFX - Subtraction Operation
- JavaFX Path Objects
- JavaFX - Path Objects
- JavaFX - LineTo Path Object
- JavaFX - HLineTo Path Object
- JavaFX - VLineTo Path Object
- JavaFX - QuadCurveTo Path Object
- JavaFX - CubicCurveTo Path Object
- JavaFX - ArcTo Path Object
- JavaFX Color and Texture
- JavaFX - Colors
- JavaFX - Linear Gradient Pattern
- JavaFX - Radial Gradient Pattern
- JavaFX Text
- JavaFX - Text
- JavaFX Effects
- JavaFX - Effects
- JavaFX - Color Adjust Effect
- JavaFX - Color input Effect
- JavaFX - Image Input Effect
- JavaFX - Blend Effect
- JavaFX - Bloom Effect
- JavaFX - Glow Effect
- JavaFX - Box Blur Effect
- JavaFX - GaussianBlur Effect
- JavaFX - MotionBlur Effect
- JavaFX - Reflection Effect
- JavaFX - SepiaTone Effect
- JavaFX - Shadow Effect
- JavaFX - DropShadow Effect
- JavaFX - InnerShadow Effect
- JavaFX - Lighting Effect
- JavaFX - Light.Distant Effect
- JavaFX - Light.Spot Effect
- JavaFX - Point.Spot Effect
- JavaFX - DisplacementMap
- JavaFX - PerspectiveTransform
- JavaFX Transformations
- JavaFX - Transformations
- JavaFX - Rotation Transformation
- JavaFX - Scaling Transformation
- JavaFX - Translation Transformation
- JavaFX - Shearing Transformation
- JavaFX Animations
- JavaFX - Animations
- JavaFX - Rotate Transition
- JavaFX - Scale Transition
- JavaFX - Translate Transition
- JavaFX - Fade Transition
- JavaFX - Fill Transition
- JavaFX - Stroke Transition
- JavaFX - Sequential Transition
- JavaFX - Parallel Transition
- JavaFX - Pause Transition
- JavaFX - Path Transition
- JavaFX Images
- JavaFX - Images
- JavaFX 3D Shapes
- JavaFX - 3D Shapes
- JavaFX - Creating a Box
- JavaFX - Creating a Cylinder
- JavaFX - Creating a Sphere
- Properties of 3D Objects
- JavaFX - Cull Face Property
- JavaFX - Drawing Modes Property
- JavaFX - Material Property
- JavaFX Event Handling
- JavaFX - Event Handling
- JavaFX - Using Convenience Methods
- JavaFX - Event Filters
- JavaFX - Event Handlers
- JavaFX UI Controls
- JavaFX - UI Controls
- JavaFX - ListView
- JavaFX - Accordion
- JavaFX - ButtonBar
- JavaFX - ChoiceBox
- JavaFX - HTMLEditor
- JavaFX - MenuBar
- JavaFX - Pagination
- JavaFX - ProgressIndicator
- JavaFX - ScrollPane
- JavaFX - Separator
- JavaFX - Slider
- JavaFX - Spinner
- JavaFX - SplitPane
- JavaFX - TableView
- JavaFX - TabPane
- JavaFX - ToolBar
- JavaFX - TreeView
- JavaFX - Label
- JavaFX - CheckBox
- JavaFX - RadioButton
- JavaFX - TextField
- JavaFX - PasswordField
- JavaFX - FileChooser
- JavaFX - Hyperlink
- JavaFX - Tooltip
- JavaFX - Alert
- JavaFX - DatePicker
- JavaFX - TextArea
- JavaFX Charts
- JavaFX - Charts
- JavaFX - Creating Pie Chart
- JavaFX - Creating Line Chart
- JavaFX - Creating Area Chart
- JavaFX - Creating Bar Chart
- JavaFX - Creating Bubble Chart
- JavaFX - Creating Scatter Chart
- JavaFX - Creating Stacked Area Chart
- JavaFX - Creating Stacked Bar Chart
- JavaFX Layout Panes
- JavaFX - Layout Panes
- JavaFX - HBox Layout
- JavaFX - VBox Layout
- JavaFX - BorderPane Layout
- JavaFX - StackPane Layout
- JavaFX - TextFlow Layout
- JavaFX - AnchorPane Layout
- JavaFX - TilePane Layout
- JavaFX - GridPane Layout
- JavaFX - FlowPane Layout
- JavaFX CSS
- JavaFX - CSS
- Media with JavaFX
- JavaFX - Handling Media
- JavaFX - Playing Video
- JavaFX Useful Resources
- JavaFX - Quick Guide
- JavaFX - Useful Resources
- JavaFX - Discussion
JavaFX - Handling Media
In general, media refers to various means of communication such as audio, video, and other forms that can be both one-way or two-way. It is used in the form of music, movies, news, vlogs and so forth.
Since media usage became an essential part of our lives, JavaFX creators developed a set of Java APIs that enables the use of media within JavaFX applications.
Handling Media in JavaFX
To handle media, JavaFX provides javafx.scene.media package that allows developers to embed a media player within the desktop window or a web page on supported platforms for media playback. This package contains the following classes that are used in combination to handle media content −
Media − It contains pieces of information like source, resolution, and metadata of a specified media resource.
MediaPlayer − It provides the controls for playing media.
MediaView − It is a node object used to provide support for animation and other effects to the media resource.
The classes mentioned above are not independent, they are always used in the combination to create an embedded media player. All attributes and methods needed to control media playback are made available in MediaPlayer class. More specifically, the play(), stop(), and pause() methods are used to control media playback. To adjust the volume level, we use VOLUME variable. The range of volume level is from 0 to 1.0 (the maximum value).
Remember, without the MediaView class, we can't view the media being played by media player.
There are some other additional methods that are used to handle the following events −
Buffers data
Whenever any errors of the MediaErrorEvent class occur.
When media stops because media player has not received data fast enough to continue playing.
When the media player reaches the end of media.
Supported format of Media in JavaFX
The following media formats are supported in JavaFX −
S.No | Media & Format |
---|---|
1 | Audio MP3, AIFF , WAV, and MPEG-4 |
2 | Video FLV containing VP6 video and MP3 audio, and MPEG-4 |
Features provided by JavaFX media
The following features are provided by JavaFX media on devices that support JavaFX −
It supports multiple playback functions, such as Play, Pause, Stop, Volume, and Mute.
It allows navigation through audio/video in a forward or backward direction as needed.
It provides support for HTTP and File protocols.
Progressive download
It also supports HTTP live streaming.
Handling Media Reference
Following are the classes and methods that are used for handling media in JavaFX.
Media
The Media class in the JavaFx is like a container for audio video files. It contains pieces of information like source, resolution, and metadata of a specified media resource. Some of the methods of the 'Media' class listed below are −
Sr.No. | Methods & Description |
---|---|
1 | getDuration() Retrieve the duration in seconds of the media. |
2 | getWidth() Retrieve the width in pixels of the media. |
3 | getHeight() Retrieve the height in pixels of the media. |
4 | getSource() Retrieve the source URI of the media. |
5 | getError() Return any error encountered in the media. |
MediaPlayer
The MediaPlayer class controls audio and video files and allows for functions like play, pause, and stop, making media control easy. Some of the methods of the 'MediaPlayer' class listed below are −
Sr.No. | Methods & Description |
---|---|
1 | getStatus() Retrieves the current player status. |
2 | getVolume() Retrieves the audio playback volume. |
3 | setRate() Sets the playback rate to the supplied value. |
4 | isAutoPlay() Retrieves the autoPlay property value. |
5 | getBlance() Retrieves the audio balance. |
6 | setMute() Sets the value of muteProperty(). |
7 | getStartTime() Retrieves the start time. |
8 | getStopTime() Retrieves the stop time. |
9 | getTotalDuration() Retrieves the total playback duration including all cycles (repetitions). |
10 | stop() Stops playing the media. |
MediaView
The MediaView class in JavaFX is a special class for displaying videos or media played by a MediaPlayer. Some of the methods of the 'MediaView' class listed below are −
Sr.No. | Methods & Description |
---|---|
1 | getX() Retrieves the x coordinate of the MediaView origin. |
2 | getY() Retrieves the y coordinate of the MediaView origin. |
3 | setSmooth() Sets whether to smooth the media when scaling. |
4 | getViewPort() Retrieves the rectangular viewport into the media frame. |
5 | isPreserveRatio() Sets whether to preserve the media aspect ratio when scaling. |
6 | getFitHeight() Retrieves the height of the bounding box of the resized media. |
7 | getFitWidth() Retrieves the width of the bounding box of the resized media. |
To Continue Learning Please Login
Login with Google