public class PlayBin extends Pipeline
Playbin provides a stand-alone everything-in-one abstraction for an audio and/or video player.
See upstream documentation at https://gstreamer.freedesktop.org/documentation/playback/playbin.html
It can handle both audio and video files and features
playbin is a Pipeline. It will notify the application of everything
that's happening (errors, end of stream, tags found, state changes, etc.) by
posting messages on its Bus. The application needs to watch the bus.
Playback can be initiated by setting the playbin to PLAYING state using
setState or play. Note that the state change
will take place in the background in a separate thread, when the function
returns playback is probably not happening yet and any errors might not have
occured yet. Applications using playbin should ideally be written to deal
with things completely asynchroneous.
When playback has finished (an EOS message has been received on the bus) or an error has occured (an ERROR message has been received on the bus) or the user wants to play a different track, playbin should be set back to READY or NULL state, then the input file/URI should be set to the new location and then playbin be set to PLAYING state again.
Seeking can be done using seek on the playbin element. Again,
the seek will not be executed instantaneously, but will be done in a
background thread. When the seek call returns the seek will most likely still
be in process. An application may wait for the seek to finish (or fail) using
Element.getState(long) with -1 as the timeout, but this will block the user
interface and is not recommended at all.
Applications may query the current position and duration of the stream via
Pipeline.queryPosition(java.util.concurrent.TimeUnit) and Pipeline.queryDuration(java.util.concurrent.TimeUnit) and setting the format
passed to Format.TIME. If the query was successful, the duration or
position will have been returned in units of nanoseconds.
| Modifier and Type | Class and Description |
|---|---|
static interface |
PlayBin.ABOUT_TO_FINISH
Signal emitted when the current uri is about to finish.
|
static interface |
PlayBin.AUDIO_CHANGED
Signal is emitted whenever the number or order of the audio streams has
changed.
|
static interface |
PlayBin.AUDIO_TAGS_CHANGED
Signal is emitted whenever the tags of an audio stream have changed.
|
static interface |
PlayBin.ELEMENT_SETUP
This signal is emitted when a new element is added to playbin or any of
its sub-bins.
|
static interface |
PlayBin.SOURCE_SETUP
This signal is emitted after the source element has been created, so it
can be configured by setting additional properties (e.g.
|
static interface |
PlayBin.TEXT_CHANGED
Signal is emitted whenever the number or order of the audio streams has
changed.
|
static interface |
PlayBin.TEXT_TAGS_CHANGED
Signal is emitted whenever the tags of a text stream have changed.
|
static interface |
PlayBin.VIDEO_CHANGED
Signal is emitted whenever the number or order of the video streams has
changed.
|
static interface |
PlayBin.VIDEO_TAGS_CHANGED
Signal is emitted whenever the tags of a video stream have changed.
|
Bin.DebugGraphDetails, Bin.DEEP_ELEMENT_ADDED, Bin.DEEP_ELEMENT_REMOVED, Bin.DO_LATENCY, Bin.ELEMENT_ADDED, Bin.ELEMENT_REMOVEDElement.NO_MORE_PADS, Element.PAD_ADDED, Element.PAD_REMOVEDGObject.GCallback, GObject.GInterfaceNativeObject.Initializer, NativeObject.TypeProvider, NativeObject.TypeRegistration<T extends NativeObject>| Modifier and Type | Field and Description |
|---|---|
static String |
GST_NAME |
static String |
GTYPE_NAME |
| Constructor and Description |
|---|
PlayBin(String name)
Creates a new PlayBin.
|
PlayBin(String name,
URI uri)
Creates a new PlayBin.
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect(PlayBin.ABOUT_TO_FINISH listener)
Adds a listener for the
about-to-finish signal |
void |
connect(PlayBin.AUDIO_CHANGED listener)
Adds a listener for the
audio-changed signal |
void |
connect(PlayBin.AUDIO_TAGS_CHANGED listener)
Adds a listener for the
audio-tags-changed signal |
void |
connect(PlayBin.ELEMENT_SETUP listener)
Add a listener for the
element-setup signal. |
void |
connect(PlayBin.SOURCE_SETUP listener)
Add a listener for the
source-setup signal. |
void |
connect(PlayBin.TEXT_CHANGED listener)
Adds a listener for the
audio-changed signal |
void |
connect(PlayBin.TEXT_TAGS_CHANGED listener)
Adds a listener for the
audio-tags-changed signal |
void |
connect(PlayBin.VIDEO_CHANGED listener)
Adds a listener for the
video-changed signal |
void |
connect(PlayBin.VIDEO_TAGS_CHANGED listener)
Adds a listener for the
video-tags-changed signal |
void |
disconnect(PlayBin.ABOUT_TO_FINISH listener)
Removes a listener for the
about-to-finish signal |
void |
disconnect(PlayBin.AUDIO_CHANGED listener)
Removes a listener for the
audio-changed signal |
void |
disconnect(PlayBin.AUDIO_TAGS_CHANGED listener)
Removes a listener for the
audio-tags-changed signal |
void |
disconnect(PlayBin.ELEMENT_SETUP listener)
Remove listener for the
element-setup signal. |
void |
disconnect(PlayBin.SOURCE_SETUP listener)
Remove listener for the
source-setup signal. |
void |
disconnect(PlayBin.TEXT_CHANGED listener)
Removes a listener for the
text-changed signal |
void |
disconnect(PlayBin.TEXT_TAGS_CHANGED listener)
Removes a listener for the
text-tags-changed signal |
void |
disconnect(PlayBin.VIDEO_CHANGED listener)
Removes a listener for the
video-changed signal |
void |
disconnect(PlayBin.VIDEO_TAGS_CHANGED listener)
Removes a listener for the
video-tags-changed signal |
Pad |
getAudioPad(int audioStreamIndex)
Retrieve the stream-combiner sinkpad for a specific text stream.
|
TagList |
getAudioTags(int audioStreamIndex)
Retrieve the tags of a specific audio stream number.
|
int |
getCurrentAudio()
Get the currently playing audio stream.
|
int |
getCurrentText()
Get the currently playing text stream.
|
Set<PlayFlags> |
getFlags()
Get the current flags set on this PlayBin.
|
int |
getNAudio()
Get the total number of available audio streams.
|
int |
getNText()
Get the total number of available text streams.
|
Pad |
getTextPad(int textStreamIndex)
Retrieve the stream-combiner sinkpad for a specific text stream.
|
TagList |
getTextTags(int textStreamIndex)
Retrieve the tags of a specific text stream number.
|
double |
getVolume()
Gets the current volume.
|
void |
setAudioSink(Element element)
Sets the audio output Element.
|
void |
setCurrentAudio(int n)
Set the currently playing audio stream.
|
void |
setCurrentText(int n)
Set the currently playing text stream.
|
void |
setFlags(Set<PlayFlags> flags)
Set the flags to control the behaviour of this PlayBin.
|
void |
setInputFile(File file)
Sets the media file to play.
|
void |
setTextSink(Element element)
Sets the text output Element.
|
void |
setURI(URI uri)
Sets the media URI to play.
|
void |
setVideoSink(Element element)
Sets the video output Element.
|
void |
setVisualization(Element element)
Sets the visualization output Element.
|
void |
setVolume(double volume)
Sets the audio playback volume.
|
getAutoFlushBus, getBus, getClock, queryDuration, queryDuration, queryPosition, queryPosition, querySegment, querySegment, seek, seek, seek, seek, setAutoFlushBus, setClock, useClockadd, addMany, connect, connect, connect, connect, connect, debugToDotFile, debugToDotFileWithTS, disconnect, disconnect, disconnect, disconnect, disconnect, getElementByName, getElementByNameRecurseUp, getElements, getElementsRecursive, getElementsSorted, getSinks, getSources, remove, removeManyaddPad, connect, connect, connect, disconnect, disconnect, disconnect, getBaseTime, getContext, getFactory, getPads, getRequestPad, getSinkPads, getSrcPads, getStartTime, getState, getState, getState, getState, getStaticPad, isPlaying, link, linkFiltered, linkMany, linkPads, linkPadsFiltered, makeRawElement, pause, play, postMessage, query, ready, releaseRequestPad, removePad, seekSimple, sendEvent, setBaseTime, setCaps, setContext, setLockedState, setStartTime, setState, stop, syncStateWithParent, unlink, unlinkMany, unlinkPadsaddControlBinding, getAsString, getControlBinding, getName, getParent, hasActiveControlBindings, removeControlBinding, setAsString, setControlBindingDisabled, setControlBindingsDisabled, setName, suggestNextSync, syncValues, toStringaddCallback, connect, connect, disconnect, dispose, emit, emit, get, getPropertyDefaultValue, getPropertyMaximumValue, getPropertyMinimumValue, getRefCount, getTypeName, invalidate, listPropertyNames, removeCallback, setclose, disown, equals, getPointer, getRawPointer, hashCodepublic static final String GST_NAME
public static final String GTYPE_NAME
public PlayBin(String name)
name - The name used to identify this pipeline.public void setInputFile(File file)
file - The File to play.public void setAudioSink(Element element)
To disable audio output, call this method with a null argument.
element - The element to use for audio output.public void setVideoSink(Element element)
To disable video output, call this method with a null argument.
element - The element to use for video output.public void setTextSink(Element element)
To disable text output, call this method with a null argument.
element - The element to use for text output.public void setVisualization(Element element)
element - The element to use for visualization.public void setFlags(Set<PlayFlags> flags)
The default value is soft-colorbalance+deinterlace+soft-volume+text+audio+video
See individual PlayFlags value descriptions for more information.
flags - set of PlayFlagspublic Set<PlayFlags> getFlags()
setFlags(java.util.Set).PlayFlagspublic void setVolume(double volume)
volume - value between 0.0 and 1.0 with 1.0 being full volume.public double getVolume()
public int getCurrentAudio()
public void setCurrentAudio(int n)
n - audio stream index to switch to (index is zero based).public int getNAudio()
public Pad getAudioPad(int audioStreamIndex)
audioStreamIndex - a text stream numberpublic TagList getAudioTags(int audioStreamIndex)
audioStreamIndex - an audio stream numbernull when the stream number
does not exist.public int getCurrentText()
public void setCurrentText(int n)
n - text stream index to switch to (index is zero based).public int getNText()
public Pad getTextPad(int textStreamIndex)
textStreamIndex - a text stream numbernull when the stream number does not exist.public TagList getTextTags(int textStreamIndex)
textStreamIndex - a text stream numbernull when the stream number
does not exist.public void connect(PlayBin.ABOUT_TO_FINISH listener)
about-to-finish signalpublic void disconnect(PlayBin.ABOUT_TO_FINISH listener)
about-to-finish signallistener - The listener that was previously added.public void connect(PlayBin.VIDEO_CHANGED listener)
video-changed signalpublic void disconnect(PlayBin.VIDEO_CHANGED listener)
video-changed signallistener - The listener that was previously added.public void connect(PlayBin.AUDIO_CHANGED listener)
audio-changed signalpublic void disconnect(PlayBin.AUDIO_CHANGED listener)
audio-changed signallistener - The listener that was previously added.public void connect(PlayBin.TEXT_CHANGED listener)
audio-changed signalpublic void disconnect(PlayBin.TEXT_CHANGED listener)
text-changed signallistener - The listener that was previously added.public void connect(PlayBin.VIDEO_TAGS_CHANGED listener)
video-tags-changed signalpublic void disconnect(PlayBin.VIDEO_TAGS_CHANGED listener)
video-tags-changed signallistener - The listener that was previously added.public void connect(PlayBin.AUDIO_TAGS_CHANGED listener)
audio-tags-changed signalpublic void disconnect(PlayBin.AUDIO_TAGS_CHANGED listener)
audio-tags-changed signallistener - The listener that was previously added.public void connect(PlayBin.TEXT_TAGS_CHANGED listener)
audio-tags-changed signalpublic void disconnect(PlayBin.TEXT_TAGS_CHANGED listener)
text-tags-changed signallistener - The listener that was previously added.@Gst.Since(minor=10) public void connect(PlayBin.ELEMENT_SETUP listener)
element-setup signal.listener - listener to add@Gst.Since(minor=10) public void disconnect(PlayBin.ELEMENT_SETUP listener)
element-setup signal.listener - listener to removepublic void connect(PlayBin.SOURCE_SETUP listener)
source-setup signal.listener - listener to addpublic void disconnect(PlayBin.SOURCE_SETUP listener)
source-setup signal.listener - listener to removeCopyright © 2021 gstreamer-java. All rights reserved.