VideoPlayer

Introduction

VideoPlayer widget in Supervisely is a media player that utilizes the HTML <video> tag and provides additional functionalities to control it through Python code such as seeking and controlling the current playback time in seconds. It uses the built-in browser player, which is supported by most devices.

In addition, Video Player has a feature for overlaying an image on top of the video without modifying the video itself.

Function signature

VideoPlayer(url=None, mime_type="video/mp4", widget_id=None)

videoplayer-default

Parameters

Parameters
Type
Description

url

str

Video url or local path to video on the host

mime_type

str

Video type

widget_id

str

ID of the widget

url

Video url or local path to video on the host. Determines the video to be displayed on widget.

type: str

default value: None

mime_type

Determines video type.

type: str

default value: video/mp4

widget_id

ID of the widget.

type: str

default value: None

Methods and attributes

Attributes and Methods
Description

url

Get url property.

mime_type

Get mime_type property.

set_video(url: str, mime_type: str = "video/mp4")

Set video in VideoPlayer widget by url.

play()

Start video to play.

pause()

Stop video playback.

get_current_timestamp()

Return current video playing step.

set_current_timestamp(value: int)

Set current video playing step.

draw_mask(path: str)

Draw a mask image on top of the video without changing video.

hide_mask()

Hide the drawn mask from the video.

Mini App Example

You can find this example in our Github repository:

ui-widgets-demos/media/005_video_player/src/main.py

Import libraries

Init API client

First, we load environment variables with credentials and init API for communicating with Supervisely Instance:

Prepare videos url and type

Initialize VideoPlayer widgets we will use in UI

Create a video control form

Create app layout

Prepare a layout for app using Card widget with the content parameter and place widget that we've just created in the Container widget.

Create app using layout

Define static_dir parameter for using files from local directory. Create an app object with layout parameter.

Handle button clicks

Use the decorator as shown below to handle button click. We have 4 buttons: to play video, to stop video, to get timestamp, to set timestamp.

Last updated

Was this helpful?