「小程序JAVA实战」小程序视频上传方法的抽象复用(56)

栏目: Java · 发布时间: 7年前

内容简介:在用户中心有视频上传,在视频展示的时候也是视频上传,如何将这个js抽象出来是个关键,现在咱们尝试抽离到公共js中,方便调用。源码https://github.com/limingios/wxProgram.git 中No.15

在用户中心有视频上传,在视频展示的时候也是视频上传,如何将这个js抽象出来是个关键,现在咱们尝试抽离到公共js中,方便调用。源码https://github.com/limingios/wxProgram.git 中No.15

抽象方法的步骤

  • 新建公共js

「小程序 <a href='https://www.codercto.com/topics/22013.html'>JAVA</a> 实战」小程序视频上传方法的抽象复用(56)

  • 找到mine中视频上传的代码拷贝到videoUtils.js中,并修改里面的内容
function uploadVideo() {
  var me = this
  wx.chooseVideo({
    sourceType: ['album', 'camera'],
    success: function (res) {
      console.log(res);
      var tempDuration = res.duration;
      var tempHeight = res.height;
      var tempWidth = res.width;
      var tempSize = res.size;
      var tempFilePath = res.tempFilePath;
      var thumbTempFilePath = res.thumbTempFilePath;
      if (tempDuration > 20) {
        wx.showToast({
          title: "视频太长了老铁不稳~",
          icon: 'none',
          duration: 3000
        })
      } else if (tempDuration < 5) {
        wx.showToast({
          title: "视频太短了不到5秒。老铁不稳~",
          icon: 'none',
          duration: 3000
        })
      } else {
        wx.navigateTo({
          url: '../chooseBgm/chooseBgm?tempDuration=' + tempDuration
            + '&tempHeight=' + tempHeight
            + '&tempWidth=' + tempWidth
            + '&tempSize=' + tempSize
            + '&tempFilePath=' + tempFilePath
            + '&thumbTempFilePath=' + thumbTempFilePath
        })
      }
    }
  })
}

#导出方法,并关联方法名称
module.exports={
  uploadVideo: uploadVideo
}

「小程序JAVA实战」小程序视频上传方法的抽象复用(56)

  • 需要使用的地方添加方法引入

    >定义名称,require引入,在需要的方法里面直接定义的名称点导出的方法就可以了。

var videoUtils = require('../../utils/videoUtils.js')
Page({

  data: {
    cover:'cover',
    videoContext:""
  },
  showSearch:function(){
    wx.navigateTo({
      url: '../videoSearch/videoSearch',
    })
  },
  onLoad:function(){
    var me = this;
    me.videoContext = wx.createVideoContext('myVideo', me);

  },
  onShow:function(){
    var me = this;
    me.videoContext.play();
  },
  onHide:function(){
    var me = this;
    me.videoContext.pause();
  },
  upload:function(){
    videoUtils.uploadVideo();
  }
})

「小程序JAVA实战」小程序视频上传方法的抽象复用(56)

PS:目前用到了两次导入的方式,第一次第三方搜索组件的时候,第二次是视频上传。

百度未收录

>>原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!

>>原文链接地址:


以上所述就是小编给大家介绍的《「小程序JAVA实战」小程序视频上传方法的抽象复用(56)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Art of Computer Programming, Volume 4,  Fascicle 3

The Art of Computer Programming, Volume 4, Fascicle 3

Donald E. Knuth / Addison-Wesley Professional / 2005-08-05 / USD 19.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 4, Fascicle 3》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具