Audio and video

Updated at:

Introduction

Audio and video is a medium that combines sound with moving images. You can use this component to display this type of digital content.

image

Configuration items

Category

Configuration

Example

Description

Content

URL

image

The URL of the video file.

Poster

image

The image displayed before the video loads or plays.

Interaction

Hide

Hides the component. For more information, see Common properties.

Autoplay

Specifies whether to automatically play the video after it loads. Because of browser restrictions, autoplayed videos are muted by default.

Loop playback

Specifies whether to loop the video.

Volume settings

Sets the volume for the audio and video.

Style

Margin

The outer margin. For more information, see Common properties.

Height

The height. For more information, see Common properties.

Content fit

Configurable when the height is not set to auto. The properties are `cover`, `contain`, and `fill`.

Control panel

The control panel for the audio and video.

CSS style

Blur

The blur effect. The unit is px. A larger number creates more blur. The default value is 0 px.

Grayscale

The value ranges from 0 to 1. The default value is 0.

Brightness

The value usually ranges from 0 to 100. The default value is 1.

Contrast

The value usually ranges from 0 to 100. The default value is 1.

Saturation

The value usually ranges from 0 to 100. The default value is 1.

Properties and methods

Name

Type

Example

Description

src

string

video.src

The URL of the video file.

poster

string

video.poster

The image displayed before the video loads or plays.

objectFit

string

video.objectFit

The content fit mode for the audio and video.

muted

boolean

video.muted

The mute status of the audio and video.

play

func

video.play()

Plays the audio and video.

pause

func

video.pause()

Pauses the audio and video.

getProgress

func

video.getProgress()

Gets the progress data of the audio and video. This API returns an object of the type { currentTime: number; duration: number; }.

setSrc

func

video.setSrc('')

Sets the URL of the video file.

setPoster

func

video.setPoster('')

Sets the image to display before the video loads or plays.

setObjectFit

func

video.setObjectFit('cover')

Sets the content fit mode for the audio and video.

setMuted

func

video.setMuted(false)

Sets the mute status of the audio and video. If you unmute the video (false) when the volume is 0, the volume is automatically set to 0.2.

clearSrc

func

video.clearSrc()

Clears the source URL data of the audio and video.

clearPoster

func

video.clearPoster()

Clears the poster data of the audio and video.

clearObjectFit

func

video.clearObjectFit()

Clears the content fit mode data of the audio and video.

clearMuted

func

video.clearMuted()

Clears the mute status data of the audio and video.

Event callbacks

Configuration

Description

The event triggered after the audio and video starts playing.

The event triggered after the audio and video is paused.

The event triggered after the audio and video finishes playing.

The event triggered after a playback error occurs.

The callback event for playback progress.

Scenario example

  • Display playback progress while a video is playing

    • As shown in the figure, configure an event handler to listen for the playback progress event. Use the progress API to retrieve the playback progress data. After processing the data, use the `setText` method to assign it to the text component.

    • This configuration displays the playback progress while the video is playing.

      image