作者:詹姵慧3482 | 来源:互联网 | 2023-10-11 09:16
视频标题: 上传视频封面 {sourcell}}" src='{{sourcel}}' /> -->上传视频封面 {poster}}" src="{{poster}}" mode="aspectFill" bindtap="chooseVideo"/> --> {poster}}" src="{{poster}}" mode="aspectFill"/> --> 上传视频
/* pages/video/video.wxss */ .main{width:100%; } .playerInfo{} .video{/* border :2rpx solid #cccccc; */ } .videoContent{display: flex;align-items: center;justify-content: center;width: 200rpx;height: 146rpx;background: #F5F5F5;position: relative; } /*播放小图标*/ .playImg{position: absolute;top: 36%;left:46%;width:64rpx;height: 64rpx; } .footerbtn{display: flex;margin-top: 20rpx; } .button{width:40%; } .videoUrlResult{width: 100%;margin-top: 20rpx; } .videoUrlResult .title{ font-size: 28rpx;font-weight: bold;color: red;margin-left: 20rpx; }/* ------------ */.userflex{display: flex;justify-content: flex-start;align-items: center;margin: 70rpx 0; } .mylistname{ font-size: 28rpx; font-weight: 700; } .weui-input{ margin-left: 40rpx; } .shipin{width: 200rpx; height: 146rpx; background: #F5F5F5; border-radius: 6rpx; position: relative; } .shangtext{font-size: 32rpx; font-weight: 700; margin-bottom: 30rpx; } .tiajiaimg{position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);width: 34rpx;height: 34rpx;} .playImgl{width: 100%;height: 100%; } .baocun{margin-top: 140rpx; width: 100%; height: 86rpx; background: #7CAAFF; border-radius: 43px; text-align: center; line-height: 86rpx; font-size: 32rpx; color: #FFF; } .tiajiaimgm{width: 100%;height: 100%; }
var app=getApp() Page({/*** 页面的初始数据*/data: {thumbTempFilePath:"",name:"",video_upload:"",// -------------videoUrl:"",poster:"",clickFlag:true, //防重复点击 source:"../../images/tiajial.png",lte:true},name(e) {console.log("name",e.detail.value);this.setData({name: e.detail.value})},uploadimg: function () {var that = this;wx.chooseImage({ //从本地相册选择图片或使用相机拍照count: 1, // 默认9sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有success: function (res) {var tempFilePaths = res.tempFilePathswx.uploadFile({url: app.globalData.baseUrl + "/Video/video_upload_img",filePath: tempFilePaths[0],name: 'file',formData: {file: tempFilePaths[0],},success: function (res) {var jso = JSON.parse(res.data)console.log("单图", jso.data);that.setData({source: jso.data,lte: false})}})}})},/*** 生命周期函数--监听页面加载*/onLoad: function (options) {},/*** 生命周期函数--监听页面显示*/onShow: function () {},/*** 拍摄或选择视频并上传服务器*/chooseVideo: function () {console.log("chooseVideo")this.setData({clickFlag: false})let that = this//1.拍摄视频或从手机相册中选择视频wx.chooseMedia({sourceType: ['album', 'camera'], // album 从相册选视频,camera 使用相机拍摄// maxDuration: 60, // 拍摄视频最长拍摄时间,单位秒。最长支持60秒camera: 'back',//默认拉起的是前置或者后置摄像头,默认backcompressed: true,//是否压缩所选择的视频文件success: function(res){console.log("说裸图",res)var thumbnail = res.tempFiles[0]let tempFilePath = thumbnail.tempFilePath//选择定视频的临时文件路径(本地路径)let thumbTempFilePath=thumbnail.thumbTempFilePathlet duration = res.duration //选定视频的时间长度let size = parseFloat(res.size/1024/1024).toFixed(1) //选定视频的数据量大小// let height = res.height //返回选定视频的高度// let width = res.width //返回选中视频的宽度 that.setData({thumbTempFilePath:thumbTempFilePath})that.data.duration = durationif(parseFloat(size) > 100){that.setData({clickFlag: false,duration: ''})let beyOndSize= parseFloat(size) - 100wx.showToast({title: '上传的视频大小超限,超出'+beyondSize+'MB,请重新上传',//image: '',//自定义图标的本地路径,image的优先级高于iconicon:'none'})}else{//2.本地视频资源上传到服务器that.uploadFile(tempFilePath)}},fail: function() {// fail},complete: function() {// complete}})},/*** 将本地资源上传到服务器* */uploadFile:function(tempFilePath){let that = thislet third_session = wx.getStorageSync('third_session')wx.showLoading({title: '上传进度:0%',mask: true //是否显示透明蒙层,防止触摸穿透})const uploadTask = wx.uploadFile({url: app.globalData.baseUrl + "/Video/video_upload",//开发者服务器地址filePath:tempFilePath,//要上传文件资源的路径(本地路径)name:'file',//文件对应key,开发者在服务端可以通过这个 key 获取文件的二进制内容// header: {}, // 设置请求的 headerformData: {third_session: third_session,// workerid :wx.getStorageSync('workeridl')}, // HTTP 请求中其他额外的 form datasuccess: function(res){console.log("uploadFile",res)// successlet data = JSON.parse(res.data)wx.hideLoading()// if(data.returnCode == 200){that.setData({video_upload:data.data,videoUrl: data.videoUrl,poster: data.imgUrl,duration: that.data.duration,// clickFlag:true})// wx.showToast({// title: '上传成功',// icon: 'success'// })// }else{// that.setData({// videoUrl: '',// poster: '',// duration: '',// clickFlag:true// })// wx.showToast({// title: '上传失败',// icon: 'none'// })// }},fail: function() {// failwx.hideLoading()that.setData({videoUrl: '',poster: '',duration: '',clickFlag:true})wx.showToast({title: '上传失败',icon: 'none'})}})//监听上传进度变化事件uploadTask.onProgressUpdate((res) =>{wx.showLoading({title: ''+res.progress+'%',mask: true //是否显示透明蒙层,防止触摸穿透})console.log("上传进度",res.progress)console.log("已经上传的数据长度,单位 Bytes:",res.totalBytesSent)console.log("预期需要上传的数据总长度,单位 Bytes:",res.totalBytesExpectedToSend)})},//保存数据库saveVideo(){console.log(this.data.video_upload);//调用服务器保存视频信息接口wx.request({url: app.globalData.baseUrl + "/Video/setVideo",data: {workerid:wx.getStorageSync('workeridl') ,title :this.data.name ,imageurl:this.data.source ,videourl: this.data.video_upload},method: 'post',success: function (res) {console.log("dasxzv",res);wx.showToast({title: '上传成功',icon: 'success'})},fail: function() {wx.showToast({title: '上传失败',icon: 'none'})}});} })
{"navigationBarTitleText": "发布视频","usingComponents": {} }