在用戶中心有視頻上傳,在視頻展現的時候也是視頻上傳,如何將這個js抽象出來是個關鍵,如今我們嘗試抽離到公共js中,方便調用。源碼https://github.com/limingios/wxProgram.git 中No.15ios
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
}
複製代碼
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();
}
})
複製代碼
PS:目前用到了兩次導入的方式,第一次第三方搜索組件的時候,第二次是視頻上傳。git