登录  /  注册
博主信息
博文 42
粉丝 2
评论 0
访问量 52632
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
微信小程序api 点赞 评论 暂停 循环播放 . (2019年3月29日)
小明的博客
原创
1101人浏览过

点赞功能

  1. 在点赞图标组件上绑定方法zan
    1. <!-- 点赞按钮 -->
    2. <image wx:if="{{item.is_zan == 0}}" class="right_img" src="../../img/love.png" bindtap="zan" data-id="{{item.id}}" data-key="{{key}}"></image>
  2. 创建方法zan
  • 首先需要判断用户是否登陆,如果没有登陆让其确认登陆,这里简化一下,确认为uid为1的用户登陆
  • 然后在登陆的情况下 在执行点赞,把uid vid a 组合成json数据data,调用api接口链接数据
    //点赞
    1. zan: function (e) {
    2. if(!uid){
    3. wx.showModal({
    4. title: '您未登陆',
    5. content: '请登录',
    6. success (res) {
    7. if (res.confirm) {
    8. uid = 1
    9. // console.log(uid)
    10. }
    11. }
    12. })
    13. } else {
    14. var data = {
    15. vid : e.currentTarget.dataset.id,
    16. uid : uid,
    17. a : "zan"
    18. }
    19. //连接api获取数据进行处理
    20. com.post('douyin.php', data, 'zanret', this);
    21. }
  1. zanren方法处理api获取的数据,获取数据集合play,当前下标的视频的is_zan赋值为1,zan_number++;这里的下标用key来表示,值是在滑动后就获取并且在开头定义为全局变量

    1. //处理赞数据
    2. zanret : function (e) {
    3. var play = this.data.play;
    4. play[key].is_zan = 1;
    5. play[key].zan_number++;
    6. this.setData({
    7. play : play
    8. })
    9. edit_v: function(e){
    10. // console.log(e)
    11. var old = key;
    12. key = e.detail.current;
    13. wx.createVideoContext("video_" + key).seek(0);
    14. wx.createVideoContext("video_" + key).play();
    15. wx.createVideoContext("video_" + old).pause();
    16. wx.createVideoContext("video_" + old).seek(0);
    17. },

    评论功能

  2. 在评论组件绑定事件 b
    1. <!-- 消息按钮 -->
    2. <image class="right_img" src="../../img/com.png" bindtap="b" data-id="{{item.id}}" data-key="{{key}}"></image>
    3. <view class="text">{{item.msg_number}}</view>
  3. b方法与之前点赞类似,首先也是要判断是否登陆,没登录那么久让其确认登陆,登陆后,将is_p赋值为1,评论层弹出,把当前视频id赋给msg_id
    1. //评论
    2. b: function (e) {
    3. if(!uid){
    4. wx.showModal({
    5. title: '您未登陆',
    6. content: '请登录',
    7. success (res) {
    8. if (res.confirm) {
    9. uid = 1
    10. // console.log(uid)
    11. }
    12. }
    13. })
    14. } else {
    15. this.setData({
    16. is_p : 1
    17. })
    18. msg_id = e.currentTarget.dataset.id;
    19. }
    20. },
  4. 点击取消,在取消组件上绑定事件c,该方法给is_p赋值为0
    1. <!-- 弹框 评论 -->
    2. <view style="position:fixed;bottom:0rpx;" wx:if="{{is_p == 1}}">
    3. <input style="width:720rpx;background-color:#fff;padding:20rpx;" placeholder="有爱评论,说点儿好听的~" focus="true" bindinput="i"></input>
    4. <view>
    5. <button type="default" style='width:50%;float:left;' bindtap="c">取消</button>
    6. <button type="primary" style='width:50%' bindtap="d">确定</button>
    7. </view>
    8. </view>
    1. //取消评论
    2. c: function () {
    3. this.setData({
    4. is_p : 0
    5. })
    6. },
  5. 获取评论值 在评论框组件绑定事件i,该方法主要是将评论内容保存在全局变量content
    1. //将评论框的内容提取赋给变量
    2. i: function (e) {
    3. content = e.detail.value;
    4. },
  6. 点击确定 绑定事件d整合uid vid content a传给api接口,然后链接数据,将数据交给 m处理
    1. //点击确定 提交数据
    2. d: function () {
    3. var data = {
    4. a: "comment",
    5. vid: msg_id,
    6. uid: uid,
    7. content: content
    8. }
    9. com.post('douyin.php', data, 'm', this);
    10. },
    11. //确定后数据处理
    12. m: function (e) {
    13. var play = this.data.play;
    14. play[key].msg_number++;
    15. this.setData({
    16. play : play,
    17. is_p : 0
    18. })
    19. },

    暂停视频

  7. 在视频组件绑定事件z给全局变量status为开关,1为播放,0为暂停

    1. //暂停视频
    2. z : function () {
    3. // console.log(2)
    4. if(status == 1){
    5. status = 0;
    6. wx.createVideoContext("video_" + key).pause();
    7. }else {
    8. status = 1;
    9. wx.createVideoContext("video_" + key).play();
    10. }
    11. }
    1. <!-- 视频 -->
    2. <video id="video_{{key}}" autoplay="{{item.autoplay}}" initial-time="{{item.initial}}" controls="" class="wh100" src="{{item.video}}" bindtap="z" bindended="g"></video>

    循环播放

  8. 在视频播放完绑定事件g 让其播放完回退到开头继续播放
    1. //循环播放
    2. g: function () {
    3. wx.createVideoContext("video_" + key).seek(0);
    4. wx.createVideoContext("video_" + key).play();
    5. },

    完善昨天的功能

  9. 滑动切换视频后原视频停止播放并且返回开头,新视频从头播放

    1. //这里是滑块滑动时绑定的方法,用来滑动后的视频播放
    2. edit_v: function(e){
    3. // console.log(e)
    4. var old = key;
    5. key = e.detail.current;
    6. wx.createVideoContext("video_" + key).seek(0);
    7. wx.createVideoContext("video_" + key).play();
    8. wx.createVideoContext("video_" + old).pause();
    9. wx.createVideoContext("video_" + old).seek(0);
    10. },
批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学