小程序
小游戏
企业微信
微信支付
扫描小程序码分享
https://developers.weixin.qq.com/miniprogram/dev/api/media/video/VideoContext.play.html
videoContext.seek(0);
videoContext.pause();
videoContext.stop();
真机测试安卓手机无效
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
js代码:
Page({
data: {
video:[],
changeindex:0,
videoindex:[0,1]
},
onLoad: function() {
var that = this;
//读取数据库
wx.request({
url: 'https://***/video.php',
method: 'GET',
cpid: 1
header: {
'content-Type': 'application/json'
success(res) {
that.setData({
video: res.data,
});
}
})
slide(e){
var preindex=[];
if(e.detail.current==0){
preindex=[0,1];
}else if(e.detail.current==this.data.video.length-1){
preindex=[e.detail.current-1,e.detail.current];
}else{
preindex=[e.detail.current-1,e.detail.current,e.detail.current+1];
let videoid='video'+(this.data.changeindex+1);
console.log(videoid);
let videoContext=wx.createVideoContext(videoid,this);
videoid='video'+(e.detail.current+1);
videoContext=wx.createVideoContext(videoid,this);
videoContext.play();
this.setData({
changeindex:e.detail.current,
videoindex:preindex
WXML代码:
<view class="video">
<swiper class="swivideo" vertical="{{true}}" bindchange="slide">
<swiper-item wx:for="{{video}}" class="" wx:key="index">
<video id="{{item.videoplayid}}" wx:if="{{toolStr.indexOf(videoindex, index) > -1 ? true : false}}" src="{{item.videosrc}}" controls="{{false}}" loop="{{true}}" show-fullscreen-btn="{{false}}" show-play-btn="{{false}}" show-center-play-btn="{{false}}" autoplay="{{index==changeindex}}"></video>
</swiper-item>
</swiper>
</view>
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
js代码:
Page({
data: {
video:[],
changeindex:0,
videoindex:[0,1]
},
onLoad: function() {
var that = this;
//读取数据库
wx.request({
url: 'https://***/video.php',
method: 'GET',
data: {
cpid: 1
},
header: {
'content-Type': 'application/json'
},
success(res) {
that.setData({
video: res.data,
});
}
})
},
slide(e){
var preindex=[];
if(e.detail.current==0){
preindex=[0,1];
}else if(e.detail.current==this.data.video.length-1){
preindex=[e.detail.current-1,e.detail.current];
}else{
preindex=[e.detail.current-1,e.detail.current,e.detail.current+1];
}
let videoid='video'+(this.data.changeindex+1);
console.log(videoid);
let videoContext=wx.createVideoContext(videoid,this);
videoContext.seek(0);
videoContext.stop();
videoContext.pause();
videoid='video'+(e.detail.current+1);
console.log(videoid);
videoContext=wx.createVideoContext(videoid,this);
videoContext.play();
this.setData({
changeindex:e.detail.current,
videoindex:preindex
})
},
WXML代码:
<view class="video">
<swiper class="swivideo" vertical="{{true}}" bindchange="slide">
<swiper-item wx:for="{{video}}" class="" wx:key="index">
<video id="{{item.videoplayid}}" wx:if="{{toolStr.indexOf(videoindex, index) > -1 ? true : false}}" src="{{item.videosrc}}" controls="{{false}}" loop="{{true}}" show-fullscreen-btn="{{false}}" show-play-btn="{{false}}" show-center-play-btn="{{false}}" autoplay="{{index==changeindex}}"></video>
</swiper-item>
</swiper>
</view>