|
@@ -13,166 +13,66 @@ Page({
|
|
* 页面的初始数据
|
|
* 页面的初始数据
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
- video: "",
|
|
|
|
- poster: 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000',
|
|
|
|
- name: '此时此刻',
|
|
|
|
- author: '许巍',
|
|
|
|
- audiosrc: 'https://www.1ting.com/api/audio?/2020/05/18/18a_yx/01.mp3',
|
|
|
|
|
|
+ height: 0,
|
|
|
|
+ animation: {},
|
|
|
|
+ left: 750
|
|
},
|
|
},
|
|
|
|
|
|
- changeVideo:function(){
|
|
|
|
- var that = this
|
|
|
|
- var uploader = new VODUpload({
|
|
|
|
- //阿里账号ID,必须有值
|
|
|
|
- userId: "WaWQOn6gXod13WLEp8cr4ljUdvcbXJ",
|
|
|
|
- //网络原因失败时,重新上传次数,默认为3
|
|
|
|
- retryCount: 3,
|
|
|
|
- //网络原因失败时,重新上传间隔时间,默认为2秒
|
|
|
|
- retryDuration: 2,
|
|
|
|
- //开始上传
|
|
|
|
- 'onUploadstarted': function (uploadInfo) {
|
|
|
|
- console.log(uploadInfo)
|
|
|
|
- // console.log("onUploadStarted:" + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object)
|
|
|
|
- //上传方式1,需要根据uploadInfo.videoId是否有值,调用点播的不同接口获取uploadauth和uploadAddress,如果videoId有值,调用刷新视频上传凭证接口,否则调用创建视频上传凭证接口
|
|
|
|
- if (uploadInfo.videoId) {
|
|
|
|
- console.log('true');
|
|
|
|
- //如果uploadInfo.videoId存在,调用刷新视频上传凭证接口
|
|
|
|
- } else {
|
|
|
|
- console.log('false');
|
|
|
|
- //如果uploadInfo.videoId不存在,调用获取视频上传地址和凭证接口
|
|
|
|
- }
|
|
|
|
- //从点播服务获取的uploadAuth、uploadAddress和videoId,设置SDK
|
|
|
|
- uploader.setUploadAuthAndAddress(uploadInfo, that.data.uploadAuth, that.data.uploadAddress, that.data.videoId);
|
|
|
|
|
|
+ takePhoto() {
|
|
|
|
+ const ctx = wx.createCameraContext()
|
|
|
|
+ ctx.takePhoto({
|
|
|
|
+ quality: 'high',
|
|
|
|
+ success: (res) => {
|
|
|
|
+ console.log(res.tempImagePath)
|
|
},
|
|
},
|
|
- //文件上传成功
|
|
|
|
- 'onUploadSucceed': function (uploadInfo) {
|
|
|
|
- console.log("上传成功:" + JSON.stringify(uploadInfo))
|
|
|
|
- that.setData({
|
|
|
|
- poster: uploadInfo.coverUrl,
|
|
|
|
- src: uploadInfo.url
|
|
|
|
- })
|
|
|
|
- // console.log("onUploadSucceed: " + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);
|
|
|
|
- },
|
|
|
|
- //文件上传失败
|
|
|
|
- 'onUploadFailed': function (uploadInfo, code, message) {
|
|
|
|
- console.log("onUploadFailed: file:" + uploadInfo.file.name + ",code:" + code + ", message:" + message);
|
|
|
|
- },
|
|
|
|
- //文件上传进度,单位:字节
|
|
|
|
- 'onUploadProgress': function (uploadInfo, totalSize, loadedPercent) {
|
|
|
|
- // console.log("onUploadProgress:file:" + uploadInfo.file.name + ", fileSize:" + totalSize + ", percent:" + Math.ceil(loadedPercent * 100) + "%");
|
|
|
|
- },
|
|
|
|
- //上传凭证超时
|
|
|
|
- 'onUploadTokenExpired': function (uploadInfo) {
|
|
|
|
- console.log("onUploadTokenExpired");
|
|
|
|
- //实现时,根据uploadInfo.videoId调用刷新视频上传凭证接口重新获取UploadAuth
|
|
|
|
- //从点播服务刷新的uploadAuth,设置到SDK里
|
|
|
|
- uploader.resumeUploadWithAuth(uploadAuth);
|
|
|
|
- },
|
|
|
|
- //全部文件上传结束
|
|
|
|
- 'onUploadEnd': function (uploadInfo) {
|
|
|
|
- console.log("onUploadEnd: uploaded all the files");
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- wx.chooseVideo({
|
|
|
|
- camera: ['album'],
|
|
|
|
- success(res){
|
|
|
|
- var file = {url: res.tempFilePath, coverUrl: res.thumbTempFilePath};
|
|
|
|
- var userData = '{"Vod":{}}';
|
|
|
|
- const urls = urlDef.urls;
|
|
|
|
- let createUrl = urls.video_create_upload + '?title=' + res.tempFilePath + '&fileName=' + res.tempFilePath;
|
|
|
|
- util.apiPost(createUrl).then((rs) => {
|
|
|
|
-
|
|
|
|
- let d = JSON.parse(rs.data);
|
|
|
|
- // console.log('createUploadVideo ' + JSON.stringify(d));
|
|
|
|
- that.setData({
|
|
|
|
- uploadAuth : d.UploadAuth,
|
|
|
|
- uploadAddress : d.UploadAddress,
|
|
|
|
- videoId : d.VideoId,
|
|
|
|
- })
|
|
|
|
- uploader.addFile(file, null, null, null, userData)
|
|
|
|
- uploader.startUpload();
|
|
|
|
- // uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId);
|
|
|
|
- }, e => {
|
|
|
|
- console.log('createUploadVideo error ' + JSON.stringify(e));
|
|
|
|
- });
|
|
|
|
|
|
+ error(e) {
|
|
|
|
+ console.log(e.detail)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
- audioPlay: function () {
|
|
|
|
-
|
|
|
|
- // audio.src = 'https://webfs.yun.kugou.com/202102261333/6839aa7db664ae01c1f11d5185d92c13/G129/M08/1B/0B/IYcBAFxqmLKABFylADPZC9WDX8A077.mp3';
|
|
|
|
- audio.src = this.data.audioSrc
|
|
|
|
- audio.play()
|
|
|
|
- // this.audioCtx.play()
|
|
|
|
- },
|
|
|
|
- audioPause: function () {
|
|
|
|
- this.audioCtx.pause()
|
|
|
|
- },
|
|
|
|
- audio14: function () {
|
|
|
|
- this.audioCtx.seek(14)
|
|
|
|
- },
|
|
|
|
- audioStart: function () {
|
|
|
|
- this.audioCtx.seek(0)
|
|
|
|
|
|
+ scanCode:function(e){
|
|
|
|
+ console.log(JSON.stringify(e))
|
|
},
|
|
},
|
|
|
|
|
|
- startRecord:function(){
|
|
|
|
- var that = this
|
|
|
|
- wx.getSetting({
|
|
|
|
- success(res) {
|
|
|
|
- if (!res.authSetting['scope.record']) {
|
|
|
|
- wx.authorize({
|
|
|
|
- scope: 'scope.record',
|
|
|
|
- success () {
|
|
|
|
- // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
|
|
|
|
- that.getRecord()
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- that.getRecord()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ closeCamera:function(){
|
|
|
|
+ this.animation = wx.createAnimation({
|
|
|
|
+ timingFunction: 'linear',
|
|
|
|
+ duration: 500
|
|
})
|
|
})
|
|
-
|
|
|
|
|
|
+ const left = 750
|
|
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- getRecord: function () {
|
|
|
|
- const options = {}
|
|
|
|
- recordManager.start(options)
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- endRecord: function () {
|
|
|
|
- recordManager.stop()
|
|
|
|
- recordManager.onStop((res) => { //监听录音停止的事件
|
|
|
|
- console.log("监听录音停止事件",res)
|
|
|
|
- if (res.duration < 1000) {
|
|
|
|
- wx.showToast({
|
|
|
|
- title: '录音时间太短'
|
|
|
|
- })
|
|
|
|
- return;
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- var tempFilePath = res.tempFilePath; // 文件临时路径
|
|
|
|
- console.log("文件临时路径", tempFilePath)
|
|
|
|
- audio.src = tempFilePath
|
|
|
|
- audio.play()
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ this.animation.translateX(left).step()
|
|
|
|
+ this.setData({
|
|
|
|
+ animation:this.animation.export()
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
- playAudio:function(){
|
|
|
|
- this.audioContext.play()
|
|
|
|
|
|
+ showCamera:function(){
|
|
|
|
+ this.animation = wx.createAnimation({
|
|
|
|
+ timingFunction: 'linear',
|
|
|
|
+ duration: 500
|
|
|
|
+ })
|
|
|
|
+ const left = 0
|
|
|
|
+ this.animation.translateX(left).step()
|
|
|
|
+ this.setData({
|
|
|
|
+ animation:this.animation.export(),
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
onLoad: function (options) {
|
|
onLoad: function (options) {
|
|
- this.audioCtx = wx.createAudioContext('myAudio')
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ wx.getSystemInfo({
|
|
|
|
+ success: (result) => {
|
|
|
|
+ this.setData({
|
|
|
|
+ height: result.windowHeight
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|