Video

class Video(**properties: Any)

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

GtkVideo is a widget to show a GtkMediaStream with media controls.

https://docs.gtk.org/gtk4/video.png

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 Paintable API and a media framework such as Gstreamer directly.

Constructors

class Video
classmethod new() Widget

Creates a new empty GtkVideo.

classmethod new_for_file(file: File | None = None) Widget

Creates a GtkVideo to play back the given file.

Parameters:

file – a GFile

classmethod new_for_filename(filename: str | None = None) Widget

Creates a GtkVideo to play back the given filename.

This is a utility function that calls new_for_file, See that function for details.

Parameters:

filename – filename to play back

classmethod new_for_media_stream(stream: MediaStream | None = None) Widget

Creates a GtkVideo to play back the given stream.

Parameters:

stream – a GtkMediaStream

classmethod new_for_resource(resource_path: str | None = None) Widget

Creates a GtkVideo to play back the resource at the given resource_path.

This is a utility function that calls new_for_file.

Parameters:

resource_path – resource path to play back

Methods

class Video
get_autoplay() bool

Returns True if videos have been set to loop.

get_file() File | None

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

get_graphics_offload() GraphicsOffloadEnabled

Returns whether graphics offload is enabled.

See GraphicsOffload for more information on graphics offload.

Added in version 4.14.

get_loop() bool

Returns True if videos have been set to loop.

get_media_stream() MediaStream | None

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

set_autoplay(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(file: File | None = None) None

Makes self play the given file.

Parameters:

file – the file to play

set_filename(filename: str | None = None) None

Makes self play the given filename.

This is a utility function that calls set_file(),

Parameters:

filename – the filename to play

set_graphics_offload(enabled: GraphicsOffloadEnabled) None

Sets whether to enable graphics offload.

See GraphicsOffload for more information on graphics offload.

Added in version 4.14.

Parameters:

enabled – the new graphics offload status

set_loop(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(stream: MediaStream | None = 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 set_file instead.

Parameters:

stream – The media stream to play or None to unset

set_resource(resource_path: str | None = None) None

Makes self play the resource at the given resource_path.

This is a utility function that calls set_file.

Parameters:

resource_path – the resource to set

Properties

class Video
props.autoplay: bool

If the video should automatically begin playing.

props.file: File

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

props.graphics_offload: GraphicsOffloadEnabled

Whether to enable graphics offload.

Added in version 4.14.

props.loop: bool

If new media files should be set to loop.

props.media_stream: MediaStream

The media-stream played