Skip to content

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

@classmethod
def new(cls) -> Widget

Creates a new empty GtkVideo.

new_for_file

@classmethod
def new_for_file(cls, file: Gio.File | None = ...) -> Widget

Creates a GtkVideo to play back the given file.

Parameters:

  • file — a GFile

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

@classmethod
def new_for_media_stream(cls, stream: MediaStream | None = ...) -> Widget

Creates a GtkVideo to play back the given stream.

Parameters:

  • stream — a GtkMediaStream

new_for_resource

@classmethod
def new_for_resource(cls, resource_path: str | None = ...) -> Widget

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

def get_autoplay(self) -> bool

Returns True if videos have been set to loop.

get_file

def get_file(self) -> Gio.File | None

Gets the file played by self or None if not playing back a file.

get_graphics_offload

def get_graphics_offload(self) -> GraphicsOffloadEnabled

Returns whether graphics offload is enabled.

See GraphicsOffload for more information on graphics offload.

get_loop

def get_loop(self) -> bool

Returns True if videos have been set to loop.

get_media_stream

def get_media_stream(self) -> MediaStream | None

Gets the media stream managed by self or None if none.

set_autoplay

def set_autoplay(self, autoplay: bool) -> None

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

def set_file(self, file: Gio.File | None = ...) -> None

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

def set_graphics_offload(self, enabled: GraphicsOffloadEnabled | int) -> None

Sets whether to enable graphics offload.

See GraphicsOffload for more information on graphics offload.

Parameters:

  • enabled — the new graphics offload status

set_loop

def set_loop(self, loop: bool) -> None

Sets whether new files loaded by self should be set to loop.

Parameters:

  • loop — whether media streams should loop

set_media_stream

def set_media_stream(self, stream: MediaStream | None = ...) -> None

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 or None to unset

set_resource

def set_resource(self, resource_path: str | None = ...) -> None

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

autoplay: bool  # read/write

If the video should automatically begin playing.

file

file: Gio.File  # read/write

The file played by this video if the video is playing a file.

graphics_offload

graphics_offload: GraphicsOffloadEnabled | int  # read/write

Whether to enable graphics offload.

loop

loop: bool  # read/write

If new media files should be set to loop.

media_stream

media_stream: MediaStream  # read/write

The media-stream played