MediaStream#
Superclasses: Object
Subclasses: MediaFile
Implemented Interfaces: Paintable
GtkMediaStream is the integration point for media playback inside GTK.
GTK provides an implementation of the GtkMediaStream interface that
is called MediaFile.
Apart from application-facing API for stream playback, GtkMediaStream
has a number of APIs that are only useful for implementations and should
not be used in applications:
prepared,
unprepared,
update,
ended,
seek_success,
seek_failed,
gerror,
error,
error_valist.
Methods#
- class MediaStream
-
- gerror(error: GError) None#
Sets
selfinto an error state.This will pause the stream (you can check for an error via
get_errorin your GtkMediaStream.pause() implementation), abort pending seeks and mark the stream as prepared.if the stream is already in an error state, this call will be ignored and the existing error will be retained.
To unset an error, the stream must be reset via a call to
unprepared.- Parameters:
error – the
GErrorto set
- get_duration() int#
Gets the duration of the stream.
If the duration is not known, 0 will be returned.
- get_error() GError | None#
If the stream is in an error state, returns the
GErrorexplaining that state.Any type of error can be reported here depending on the implementation of the media stream.
A media stream in an error cannot be operated on, calls like
playorseekwill not have any effect.GtkMediaStreamitself does not provide a way to unset an error, but implementations may provide options. For example, aMediaFilewill unset errors when a new source is set, e.g. withset_file.
- get_volume() float#
Returns the volume of the audio for the stream.
See
set_volumefor details.
- is_prepared() bool#
Returns whether the stream has finished initializing.
At this point the existence of audio and video is known.
- is_seekable() bool#
Checks if a stream may be seekable.
This is meant to be a hint. Streams may not allow seeking even if this function returns
True. However, if this function returnsFalse, streams are guaranteed to not be seekable and user interfaces may hide controls that allow seeking.It is allowed to call
seekon a non-seekable stream, though it will not do anything.
- realize(surface: Surface) None#
Called by users to attach the media stream to a
GdkSurfacethey manage.The stream can then access the resources of
surfacefor its rendering purposes. In particular, media streams might want to create aGdkGLContextor sync to theGdkFrameClock.Whoever calls this function is responsible for calling
unrealizebefore either the stream orsurfaceget destroyed.Multiple calls to this function may happen from different users of the video, even with the same
surface. Each of these calls must be followed by its own call tounrealize.It is not required to call this function to make a media stream work.
- Parameters:
surface – a
GdkSurface
- seek(timestamp: int) None#
Start a seek operation on
selftotimestamp.If
timestampis out of range, it will be clamped.Seek operations may not finish instantly. While a seek operation is in process, the
seekingproperty will be set.When calling
seek()during an ongoing seek operation, the new seek will override any pending seek.- Parameters:
timestamp – timestamp to seek to.
- seek_failed() None#
Ends a seek operation started via GtkMediaStream.seek() as a failure.
This will not cause an error on the stream and will assume that playback continues as if no seek had happened.
See
seek_successfor the other way of ending a seek.
- seek_success() None#
Ends a seek operation started via GtkMediaStream.seek() successfully.
This function will unset the GtkMediaStream:ended property if it was set.
See
seek_failedfor the other way of ending a seek.
- set_loop(loop: bool) None#
Sets whether the stream should loop.
In this case, it will attempt to restart playback from the beginning instead of stopping at the end.
Not all streams may support looping, in particular non-seekable streams. Those streams will ignore the loop setting and just end.
- Parameters:
loop –
Trueif the stream should loop
- set_muted(muted: bool) None#
Sets whether the audio stream should be muted.
Muting a stream will cause no audio to be played, but it does not modify the volume. This means that muting and then unmuting the stream will restore the volume settings.
If the stream has no audio, calling this function will still work but it will not have an audible effect.
- Parameters:
muted –
Trueif the stream should be muted
- set_playing(playing: bool) None#
Starts or pauses playback of the stream.
- Parameters:
playing – whether to start or pause playback
- set_volume(volume: float) None#
Sets the volume of the audio stream.
This function call will work even if the stream is muted.
The given
volumeshould range from 0.0 for silence to 1.0 for as loud as possible. Values outside of this range will be clamped to the nearest value.If the stream has no audio or is muted, calling this function will still work but it will not have an immediate audible effect. When the stream is unmuted, the new volume setting will take effect.
- Parameters:
volume – New volume of the stream from 0.0 to 1.0
- stream_ended() None#
Pauses the media stream and marks it as ended.
This is a hint only, calls to
playmay still happen.The media stream must be prepared when this function is called.
Added in version 4.4.
- stream_prepared(has_audio: bool, has_video: bool, seekable: bool, duration: int) None#
Called by
GtkMediaStreamimplementations to advertise the stream being ready to play and providing details about the stream.Note that the arguments are hints. If the stream implementation cannot determine the correct values, it is better to err on the side of caution and return
True. User interfaces will use those values to determine what controls to show.This function may not be called again until the stream has been reset via
stream_unprepared.Added in version 4.4.
- Parameters:
has_audio –
Trueif the stream should advertise audio supporthas_video –
Trueif the stream should advertise video supportseekable –
Trueif the stream should advertise seekabilityduration – The duration of the stream or 0 if unknown
- stream_unprepared() None#
Resets a given media stream implementation.
stream_preparedcan then be called again.This function will also reset any error state the stream was in.
Added in version 4.4.
- unrealize(surface: Surface) None#
Undoes a previous call to
realize().This causes the stream to release all resources it had allocated from
surface.- Parameters:
surface – the
GdkSurfacethe stream was realized with
- update(timestamp: int) None#
Media stream implementations should regularly call this function to update the timestamp reported by the stream.
It is up to implementations to call this at the frequency they deem appropriate.
The media stream must be prepared when this function is called.
- Parameters:
timestamp – the new timestamp
Properties#
- class MediaStream
-
- props.error: GError#
The type of the None singleton.
Virtual Methods#
- class MediaStream
-
- do_realize(surface: Surface) None#
Called by users to attach the media stream to a
GdkSurfacethey manage.The stream can then access the resources of
surfacefor its rendering purposes. In particular, media streams might want to create aGdkGLContextor sync to theGdkFrameClock.Whoever calls this function is responsible for calling
unrealizebefore either the stream orsurfaceget destroyed.Multiple calls to this function may happen from different users of the video, even with the same
surface. Each of these calls must be followed by its own call tounrealize.It is not required to call this function to make a media stream work.
- Parameters:
surface – a
GdkSurface
- do_seek(timestamp: int) None#
Start a seek operation on
selftotimestamp.If
timestampis out of range, it will be clamped.Seek operations may not finish instantly. While a seek operation is in process, the
seekingproperty will be set.When calling
seek()during an ongoing seek operation, the new seek will override any pending seek.- Parameters:
timestamp – timestamp to seek to.
Fields#
- class MediaStream
- parent_instance#