uniapp引入微信小程序自定义视频组件--记录
2024-10-20 13:46:23
官方文档:https://zh.uniapp.dcloud.io/tutorial/miniprogram-subject.html
在 pages.json同级目录下 创建目录和文件:
wxcomponents:
my-video-play:
index.js
index.json
index.wxml
index.wxss
pages.json 全局引入:
index.js:
Component({
properties: {
videoUrl: String,
sectionId: String
},
methods: {
clickFun(event) {
this.triggerEvent('hideElement');
},
loadedmetadataFun(event) {
this.triggerEvent('loadedmetadataStart', event.detail.duration);
},
timeupdateFun(event) {
this.triggerEvent('videoTimeUpdate', event.detail);
},
endFun() {
this.triggerEvent('palyNextVideo', this.sectionId);
},
getVideoContext() {
return wx.createVideoContext("myVideo", this);
},
videoPlay() {
wx.createVideoContext("myVideo", this).play();
},
videoPause() {
wx.createVideoContext("myVideo", this).pause();
},
videoSeek(second) {
wx.createVideoContext("myVideo", this).seek(second);
}
}
})
index.wxml:
<video style="position: absolute; width: 100vw; height: 100vh;" id="myVideo"
direction="0"
src="{{videoUrl}}"
autoplay
controls="{{false}}"
show-center-play-btn="{{false}}"
show-play-btn="{{false}}"
show-fullscreen-btn="{{false}}"
enable-progress-gesture="{{false}}"
bindloadedmetadata="loadedmetadataFun"
bindtimeupdate="timeupdateFun"
bindended="endFun"
bindtap="clickFun"
>
</video>
index.json:
{
"component": true
}
index.wxss: 空文件
然后在uniapp vue文件中引入该组件:
<template>
<view>
...
<my-video-play style="position: absolute; width: 100vw; height: 100vh;" v-if="current === index && (item.videoUrl !== '')" ref='videoPlaySelf'
:videoUrl="item.videoUrl" :sectionId="item.sectionId"
@hideElement="hideElement" @loadedmetadataStart="loadedmetadataStart"
@videoTimeUpdate="videoTimeUpdate" @palyNextVideo="palyNextVideo">
</my-video-play>
...
</view>
</template>
<script lang="ts">
...
</script>
<style lang="scss" scoped>
...
</style>
最新文章
- oracle 误删数据恢复
- php的数据循环 之li的3个类判断
- REST
- if条件里比较浮点数
- (原创)Python字符串系列(1)——str对象
- Linux 链接(转载)
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-008-使用非关系型数据库时如何验证用户(自定义UserService)
- C# 关键字--using
- 上架app被拒原因总结
- jQuery中的选择器(下)
- Ext.data.Store添加动态参数
- bootstrap 基础(一)
- [poj2406]Power Strings_hash
- PostCSS 基本用法
- ZooKeeper注册中心安装详细步骤(单节点)
- Python2.x与3.x对比
- 洛谷P3722 [AH2017/HNOI2017]影魔(线段树)
- vue_模板渲染
- 函数和常用模块【day04】:函数的非固定参数(三)
- angular2.0学习笔记3.了解angular2.0项目结构