首先在wxml檔案中設定video的id
<video id='myVideo' src='{{video}}' controls='true' ></video>
然後在js檔案中透過 wx.createVideoContext 獲取VideoContext 例項
let videoCtx = null let app = getApp() Component({ properties: { }, data: { }, attached: function () { videoCtx = wx.createVideoContext('myVideo', this) }, methods: { show: function() { //進入當前頁面 }, hide: function() { //離開當前頁面 videoCtx.pause() //暫停影片 }, } })
video的使用方法:
VideoContext.play()
播放影片
VideoContext.pause()
暫停影片
VideoContext.stop()
停止影片
VideoContext.seek(number position)
跳轉到指定位置
VideoContext.sendDanmu(Object data)
傳送彈幕
VideoContext.playbackRate(number rate)
設定倍速播放
VideoContext.requestFullScreen(Object object)
進入全屏
VideoContext.exitFullScreen()
退出全屏
https://developers.weixin.qq.com/miniprogram/dev/component/video.html
https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/extended/component-plus/video-swiper.html
轉 :https://blog.csdn.net/zm_960911/article/details/100573660