public interface VideoService
Important note: The video files will be displayed on top of the JavaFX layer. This means that the developer should take care of disabling view switching any other UI interaction that could lead to overlapping nodes while the video is playing.
If the user calls hide()
or the playlist finishes, the media layer
will be removed, and the user will be able to resume normal interaction.
Example
Services.get(VideoService.class).ifPresent(service -> {
service.setControlsVisible(true);
service.getPlaylist().add("my.video.mp4");
service.play();
});
Android Configuration: none
iOS Configuration: none
Type | Property and Description |
---|---|
javafx.beans.property.IntegerProperty |
currentIndex
Integer property that indicates the current index on the playlist,
starting from 0.
|
javafx.beans.property.BooleanProperty |
fullScreen
Boolean property that indicates if the media file is playing in full
screen mode or in normal mode.
|
javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status> |
status
Read only property that indicates the media player status.
|
Modifier and Type | Method and Description |
---|---|
javafx.beans.property.IntegerProperty |
currentIndexProperty()
Integer property that indicates the current index on the playlist,
starting from 0.
|
javafx.beans.property.BooleanProperty |
fullScreenProperty()
Boolean property that indicates if the media file is playing in full
screen mode or in normal mode.
|
javafx.collections.ObservableList<java.lang.String> |
getPlaylist()
Returns an observable list with media file names.
|
void |
hide()
Removes the layer with the control, so the JavaFX layer can resume normal
interaction.
|
void |
pause()
Pauses a playing media file.
|
void |
play()
Plays a valid media file.
|
void |
setControlsVisible(boolean controlsVisible)
When set to
true the native embedded controls will be
displayed on top of the media file. |
void |
setCurrentIndex(int index)
Specifies the media file to be played at the specified index in the
initial playlist.
|
void |
setFullScreen(boolean fullScreen)
Called while the video is visible, if true displays the media file in full
screen mode.
|
void |
setLooping(boolean looping)
|
void |
setPosition(javafx.geometry.Pos alignment,
double topPadding,
double rightPadding,
double bottomPadding,
double leftPadding)
Allows setting the position of the media file.
|
void |
show()
After
adding items to the the playlist , this method can be
called to prepare the media player and the native layer on top of the JavaFX
one. |
javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status> |
statusProperty()
Read only property that indicates the media player status.
|
void |
stop()
Stops a playing media file.
|
javafx.beans.property.BooleanProperty fullScreenProperty
setFullScreen(boolean)
javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status> statusProperty
javafx.beans.property.IntegerProperty currentIndexProperty
setCurrentIndex(int)
javafx.collections.ObservableList<java.lang.String> getPlaylist()
Supported formats:
The media files (video and audio) can either be a valid URL or they can be provided in the resources folder.
For example, the following media files:
getPlaylist().addAll("media1.mp4", "video/media2.mp4",
"http://www.host.com/media3.mp4");
ObservableList
of media file names, either in the resource
folder or valid URLsvoid show()
adding items to the the playlist
, this method can be
called to prepare the media player and the native layer on top of the JavaFX
one.
Calling this method doesn't start playing. Alternatively, call play()
directly.
void play()
If the media player control wasn't created yet, it will be created first and placed in a layer on top of the JavaFX layer. If it was already created, it will start or resume playing.
void stop()
If play()
is called again, the playlist will start from the
beginning of the playlist.
void pause()
If play()
is called again, the playlist will resume from the
position the media file was at when it was paused.
void hide()
This method can be called at any time to stop and hide the media player.
It will be called automatically when the last media file in the playlist has
ended, unless looping
is set to true
.
void setPosition(javafx.geometry.Pos alignment, double topPadding, double rightPadding, double bottomPadding, double leftPadding)
alignment
- values for describing vertical and horizontal positioning
and alignmenttopPadding
- the top padding value, relative to the screenrightPadding
- the right padding value, relative to the screenbottomPadding
- the bottom padding value, relative to the screenleftPadding
- the left padding value, relative to the screenvoid setLooping(boolean looping)
true
the media files in the playlist will
be played indefinitely until stop()
or hide()
is called.
Note: calling this method must be done before starting media playback.
looping
- When true
the playlist will restart from the beginning
after all media files have been played. Default value is false
.void setControlsVisible(boolean controlsVisible)
true
the native embedded controls will be
displayed on top of the media file. Note that the controls are hidden
automatically after a few seconds and a tap on the screen might be
required to bring the controls back.
Note: calling this method must be done before starting media playback.
Media controls are also only visible for video files, not for audio.
controlsVisible
- true to show the native embedded controls. Default
value is false
.void setFullScreen(boolean fullScreen)
fullScreen
- Sets the media file in full screen. Default is falsejavafx.beans.property.BooleanProperty fullScreenProperty()
setFullScreen(boolean)
javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.media.MediaPlayer.Status> statusProperty()
void setCurrentIndex(int index)
index
- The index from the playlist that will start playingjavafx.beans.property.IntegerProperty currentIndexProperty()
setCurrentIndex(int)