官方文档: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>

最新文章

  1. oracle 误删数据恢复
  2. php的数据循环 之li的3个类判断
  3. REST
  4. if条件里比较浮点数
  5. (原创)Python字符串系列(1)——str对象
  6. Linux 链接(转载)
  7. SPRING IN ACTION 第4版笔记-第九章Securing web applications-008-使用非关系型数据库时如何验证用户(自定义UserService)
  8. C# 关键字--using
  9. 上架app被拒原因总结
  10. jQuery中的选择器(下)
  11. Ext.data.Store添加动态参数
  12. bootstrap 基础(一)
  13. [poj2406]Power Strings_hash
  14. PostCSS 基本用法
  15. ZooKeeper注册中心安装详细步骤(单节点)
  16. Python2.x与3.x对比
  17. 洛谷P3722 [AH2017/HNOI2017]影魔(线段树)
  18. vue_模板渲染
  19. 函数和常用模块【day04】:函数的非固定参数(三)
  20. angular2.0学习笔记3.了解angular2.0项目结构

热门文章

  1. idea插件Jclasslib---查看字节码指令
  2. CNCF社区首个!KubeEdge达到软件供应链SLSA L3等级
  3. c++标准库string的使用完美总结——十分详细,复习学习记忆都可以使用
  4. 【KAWAKO】TVM-tflite模型编译与优化
  5. 原创ui自动化组件库-seliky
  6. pip和pipenv简记
  7. Naughty Stone Piles
  8. CSS 数学函数与容器查询实现不定宽文本溢出跑马灯效果
  9. 使用elasticsearch-head修改一个索引的副本数
  10. web3 的身份验证之以太坊签名消息