Gtk.Video¶
class — extends Widget, Accessible, Buildable, ConstraintTarget
Shows a GtkMediaStream with media controls.
<picture> <source srcset="video-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkVideo" src="video.png"> </picture>
The controls are available separately as MediaControls.
If you just want to display a video without controls, you can treat it
like any other paintable and for example put it into a Picture.
GtkVideo aims to cover use cases such as previews, embedded animations,
etc. It supports autoplay, looping, and simple media controls. It does
not have support for video overlays, multichannel audio, device
selection, or input. If you are writing a full-fledged video player,
you may want to use the Gdk.Paintable API and a media framework
such as Gstreamer directly.
Constructors¶
new¶
Creates a new empty GtkVideo.
new_for_file¶
Creates a GtkVideo to play back the given file.
Parameters:
file— aGFile
new_for_filename¶
@classmethod
def new_for_filename(cls, filename: str | bytes | os.PathLike[str] | os.PathLike[bytes] | None = ...) -> Widget
Creates a GtkVideo to play back the given filename.
This is a utility function that calls Video.new_for_file,
See that function for details.
Parameters:
filename— filename to play back
new_for_media_stream¶
Creates a GtkVideo to play back the given stream.
Parameters:
stream— aGtkMediaStream
new_for_resource¶
Creates a GtkVideo to play back the resource at the
given resource_path.
This is a utility function that calls Video.new_for_file.
Parameters:
resource_path— resource path to play back
Methods¶
get_autoplay¶
Returns True if videos have been set to loop.
get_file¶
Gets the file played by self or None if not playing back
a file.
get_graphics_offload¶
Returns whether graphics offload is enabled.
See GraphicsOffload for more information on graphics offload.
get_loop¶
Returns True if videos have been set to loop.
get_media_stream¶
Gets the media stream managed by self or None if none.
set_autoplay¶
Sets whether self automatically starts playback when it
becomes visible or when a new file gets loaded.
Parameters:
autoplay— whether media streams should autoplay
set_file¶
Makes self play the given file.
Parameters:
file— the file to play
set_filename¶
def set_filename(self, filename: str | bytes | os.PathLike[str] | os.PathLike[bytes] | None = ...) -> None
Makes self play the given filename.
This is a utility function that calls Video.set_file,
Parameters:
filename— the filename to play
set_graphics_offload¶
Sets whether to enable graphics offload.
See GraphicsOffload for more information on graphics offload.
Parameters:
enabled— the new graphics offload status
set_loop¶
Sets whether new files loaded by self should be set to loop.
Parameters:
loop— whether media streams should loop
set_media_stream¶
Sets the media stream to be played back.
self will take full control of managing the media stream. If you
want to manage a media stream yourself, consider using a
Picture for display.
If you want to display a file, consider using Video.set_file
instead.
Parameters:
stream— The media stream to play orNoneto unset
set_resource¶
Makes self play the resource at the given resource_path.
This is a utility function that calls Video.set_file.
Parameters:
resource_path— the resource to set
Properties¶
autoplay¶
If the video should automatically begin playing.
file¶
The file played by this video if the video is playing a file.
graphics_offload¶
Whether to enable graphics offload.
loop¶
If new media files should be set to loop.
media_stream¶
The media-stream played