HomeDocs
Skip to main content

video - Video Component

Description

The video component is used to display and play videos.

Starting from the basic library version 5.1.1, you can use dlt.createVideoContext to manipulate the video component.

Properties

Property NameTypeDefault ValueRequiredDescriptionMinimum Version
srcstringYesThe resource URL of the video to be played. It supports both network paths and local temporary paths.2.0.0
loopbooleanFALSENoSpecifies whether the video should loop playback.2.0.0
mutedbooleanFALSENoSpecifies whether the video should be muted.2.0.0
controlsbooleanTRUENoSpecifies whether to display the default playback controls (play/pause button, progress, time).2.0.0
autoplaybooleanFALSENoSpecifies whether the video should start playing automatically.2.0.0
posterstringNoThe resource URL of the video's cover image. Setting poster has no effect if the controls property is set to false.2.0.0
show-fullscreen-btnbooleanTRUENoSpecifies whether to display the fullscreen button.2.0.0
bindplayeventhandleNoTriggered when the video starts or resumes playing.2.0.0
bindpauseeventhandleNoTriggered when the video is paused.2.0.0
bindendedeventhandleNoTriggered when the video reaches the end.2.0.0
bindtimeupdateeventhandleNoTriggered when the playback progress changes. event.detail = {currentTime, duration}. Triggered every 250ms.2.0.0
bindfullscreenchangeeventhandleNoTriggered when the video enters or exits fullscreen mode. event.detail = {fullScreen, direction}, where direction can be "vertical" or "horizontal".2.0.0
bindwaitingeventhandleNoTriggered when the video is buffering.2.0.0
binderroreventhandleNoTriggered when an error occurs during video playback.2.0.0
bindprogresseventhandleNoTriggered when the loading progress changes. Only supports one segment of loading.2.0.0
bindloadedmetadataeventhandleNoTriggered when the video metadata is loaded. event.detail = {width, height, duration}.2.0.0
bindcontrolstoggleeventhandleNoTriggered when the controls are toggled (show/hide).2.0.0
bindseekcompleteeventhandlerNoTriggered when seeking is completed (Triggered when the user has finished dragging the progress bar).2.0.0
bindmutedchangeeventhandlerNoTriggered when the video mute status changes. event.detail = {muted: true}, where muted is true if the video is currently muted, and false otherwise.3.6.0

Usage Example

<!-- index.dlt -->
<video
:object-fit="objectFit"
:autoplay="autoplay"
:src="src"
:show-fullscreen-btn="showFullscreenBtn"
bind:bindplay="bindplay"
bind:bindpause="bindpause"
bind:bindended="bindended"
bind:binderror="binderror"
bind:bindtimeupdate="bindtimeupdate"
bind:bindfullscreenchange="bindfullscreenchange"
data-url="data--url--content"
data-content="data--detail-content"
id="myVideo"
></video>

<view bind:tap="triggerPlay">Click to Play</view>
<view bind:tap="triggerPause">Click to Pause</view>
<view bind:tap="triggerStop">Click to Stop</view>
<view bind:tap="triggerFullscreen">Click to Enter Fullscreen</view>
<view bind:tap="triggerSeek">Jump to Specific Position</view>
// index.js
Page({
data: {
loop: true,
controls: false,
autoplay: true,
muted: true,
src: '/images/big_buck_bunny.mp4',
poster: '/images/test.png',
objectFit: 'cover',
showFullscreenBtn: false,
},
onReady() {
console.log('page ready');
this.videoContext = dlt.createVideoContext('myVideo');
},
bindplay(event) {
console.log('bindplay', event);
},
bindpause(event) {
console.log('bindpause', event);
},
bindended(event) {
console.log('bindended', event);
},
binderror(event) {
console.log('binderror', event);
},
bindtimeupdate(event) {
console.log('bindtimeupdate', event);
},
bindfullscreenchange(event) {
console.log('bindfullscreenchange', event);
},
triggerPlay() {
this.videoContext && this.videoContext.play();
},
triggerPause() {
this.videoContext && this.videoContext.pause();
},
triggerStop() {
this.videoContext && this.videoContext.stop();
},
triggerFullscreen() {
this.videoContext && this.videoContext.requestFullScreen({ direction: 0 });
// Simulate exiting fullscreen after 5 seconds
setTimeout(() => {
this.videoContext && this.videoContext.exitFullScreen();
}, 5000);
},
triggerSeek() {
// Set playback progress to 10 seconds
this.videoContext && this.videoContext.seek(10);
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.