HomeDocs
Skip to main content

Native Video Component

Introduction

Non-hierarchical native video component

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

Properties

Property NameTypeDefault ValueRequiredDescriptionMinimum Version
srcstringYesThe resource address of the video to be played, supports network paths and local temporary paths4.0.0
loopbooleanfalseNoWhether to loop the playback4.0.0
mutedbooleanfalseNoWhether to play the video muted4.0.0
autoplaybooleanfalseNoWhether to autoplay the video4.0.0
posterstringNoResource address of the video cover image4.0.0
directionnumber0NoSet the fullscreen direction; 0: normal vertical; 90: screen rotated counterclockwise 90 degrees; -90: screen rotated clockwise 90 degrees4.0.0
initial-timenumber0NoSpecify the initial playback position of the video4.0.0
cachebooleanfalseNoWhether to cache the video4.0.0
bindplayeventhandleNoTriggered when playback starts/resumes (play event)4.0.0
bindpauseeventhandleNoTriggered when playback is paused (pause event)4.0.0
bindendedeventhandleNoTriggered when the video reaches the end (ended event)4.0.0
bindtimeupdateeventhandleNoTriggered when the playback progress changes; event.detail = {currentTime, duration}. Frequency of 250ms4.0.0
bindwaitingeventhandleNoTriggered when the video is buffering4.0.0
binderroreventhandleNoTriggered when an error occurs during video playback4.0.0
bindprogresseventhandleNoTriggered when the loading progress changes; supports only one segment of loading4.0.0
bindloadedmetadataeventhandleNoTriggered when video metadata is loaded; event.detail = {width, height, duration}4.0.0
bindseekcompleteeventhandleNoTriggered when seeking is complete4.0.0
createdsuccesseventhandleNoReturned after the video component is created; event.createdsuccess = true: creation successful; event.createdsuccess = false: creation failed4.0.0

Usage Example

<!--index.dlt-->
<native-video
data-url="data--url--content"
data-content="data--detail-content"
id="myVideo"
:autoplay="autoplay"
:poster="poster"
:src="src"
bind:bindplay="bindplay"
bind:bindpause="bindpause"
bind:bindended="bindended"
bind:binderror="binderror"
bind:bindtimeupdate="bindtimeupdate"
bind:createdsuccess="createdsuccess"
>
</native-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="triggerSeek">Jump to Specific Position</view>
// index.js
Page({
data: {
autoplay: true,
src: '/images/big_buck_bunny.mp4',
poster: '/images/test.png',
},
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);
},
createdsuccess(event) {
console.log('createdsuccess result:', event.createdsuccess); // createdsuccess result:true
console.log('createdsuccess target:', event.target); // Video element DOM information
},
triggerPlay() {
this.videoContext && this.videoContext.play();
},
triggerPause() {
this.videoContext && this.videoContext.pause();
},
triggerStop() {
this.videoContext && this.videoContext.stop();
},
triggerSeek() {
// Set playback progress to 10 seconds
this.videoContext && this.videoContext.seek(10);
},
});

Error Code Correspondence

errCodeMeaning
-1STATE_ERROR
-2STATE_NETWORK_ERROR
-3STATE_PARSE_ERROR
-4STATE_URL_NULL
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.