You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
2.8 KiB
138 lines
2.8 KiB
// miniprogram/pages/previewWork/previewWork.js
|
|
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
muted: 'false',
|
|
path:'',
|
|
cloudPath: '',
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
path:options.path
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
this.videoContext = wx.createVideoContext('myVideo');
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
startPreview() {
|
|
this.videoContext.play();
|
|
wx.showToast({
|
|
title: '开始播放',
|
|
});
|
|
console.log("作品路径为" + getApp().globalData.workPath);
|
|
wx.playVoice({
|
|
filePath: getApp().globalData.workPath,
|
|
success: function () {
|
|
wx.showToast({
|
|
title: '播放结束',
|
|
})
|
|
},
|
|
})
|
|
// this.videoContext.play();
|
|
},
|
|
stopPreview(){
|
|
this.videoContext.stop();
|
|
},
|
|
onAdd(cloudpath) {//保存到云端,更新数据库
|
|
const db = wx.cloud.database(); console.log("cloudpath=" + cloudpath);
|
|
db.collection('user-video').add({
|
|
data: {
|
|
VideoPath: this.data.path,
|
|
CloudPath:cloudpath,
|
|
},
|
|
success: res => {
|
|
// 在返回结果中会包含新创建的记录的 _id
|
|
this.setData({
|
|
cloudPath: cloudpath
|
|
})
|
|
wx.showToast({
|
|
title: '新增记录成功',
|
|
})
|
|
console.log('[数据库] [新增记录] 成功,记录 _id: ', res._id)
|
|
},
|
|
fail: err => {
|
|
wx.showToast({
|
|
icon: 'none',
|
|
title: '新增记录失败'
|
|
})
|
|
console.error('[数据库] [新增记录] 失败:', err)
|
|
}
|
|
})
|
|
},
|
|
saveWork() {//保存作品并上传云存储
|
|
var path;
|
|
var length=this.data.path.length-4;
|
|
var index = this.data.path.substring(80,length);
|
|
console.log("index=" + index);//'/VideoWork/' + getApp().globalData.openid+index+'.mp3'
|
|
wx.cloud.uploadFile({
|
|
cloudPath: 'VideoWork/' + index + getApp().globalData.openid+'.mp3',
|
|
filePath: getApp().globalData.workPath,
|
|
success: res => {
|
|
path = res.fileID;
|
|
console.log("保存成功"+path);
|
|
this.onAdd(path);
|
|
},
|
|
fail: err => {
|
|
console.log("保存失败");
|
|
}
|
|
})
|
|
},
|
|
onShareAppMessage: function () {
|
|
|
|
},
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |