创建视频列表的问题
发布于 5 年前 作者 jbai 9459 次浏览 来自 问答

我创建了一个视频列表,代码如下:

<view class="container">
 
    <scroll-view scroll-y="true" class="container">
        <view class="zan-card video-item" wx:for="{{videos}}">  
            <view class="feed-intro zan-c-gray-darker zan-font-16">
                <text class="feed-txt">{{item.intro}}</text>
            </view>
            <view class="feed-content">
                <view class="video">
                    <video id="video{{index}}" data-id="{{index}}" src="{{item.videoUrl}}" objectFit="contain" poster="{{item.coverUrl}}" controls></video>
                </view>
            </view>
             
        </view>
    </scroll-view>
</view>

但是有几个问题,问题为:

1、设置的是不自动播放一打开页面所有视频就开始发请求加载。我想做的是点哪个哪个播放,并且是在当前页面播放。

2、我看规范说不能在score-view中用video 会有什么问题吗。我想做的就是在当前页面播放。

3、如何点击当前视频其他视频暂停。我得代码如下,但是好像不可以。

startPlay: function (e) {
        var index = e.currentTarget.dataset.id;
        var videoContext = wx.createVideoContext("video" + index);
        var i=0;
        for(i=0;i<10;i++){
            wx.createVideoContext("video" + i).pause();//其他的都暂停
        }
        videoContext.play();//当前的开始
         
    }

手机型号是 iphone 6 plus

小程序版本是最新版本1.01.1711020

2 回复

请问一下,startPlay是绑定在video上的bindTap时间么?

startPlay: function (e) {
        var curVideoId = e.currentTarget.id;
 
        if (this.data.prevVideoId) {
            var prevV = wx.createVideoContext(this.data.prevVideoId);
            prevV.pause()
 
        }
 
        var videoContext = wx.createVideoContext(curVideoId);
         
        videoContext.play();
        this.setData({
            prevVideoId: curVideoId
        });
         
    }

第三个问题解决了

回到顶部