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.
158 lines
3.0 KiB
158 lines
3.0 KiB
5 years ago
|
// miniprogram/pages/Dubbing/Dubbing.js
|
||
|
var Path=''
|
||
|
const myRecord = wx.getRecorderManager()
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
|
||
|
data: {
|
||
|
isSpeaking: false,//是否正在说话
|
||
|
voices: [],//音频数组:
|
||
|
muted:'false',
|
||
|
path:''
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
Path= options.path;
|
||
|
var a=Path.length;
|
||
|
Path=Path.substring(0, a - 5) + '.mp4'
|
||
|
this.setData({
|
||
|
path: Path//根据图片路径得到相应的视频路径
|
||
|
});
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady: function () {
|
||
|
this.videoContext = wx.createVideoContext('myVideo');
|
||
|
|
||
|
},
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 用户点击右上角分享
|
||
|
*/
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
funended: function () {
|
||
|
console.log('录音结束');
|
||
|
myRecord.stop();
|
||
|
wx.navigateTo({//视频播放完成自动跳转到预览页面
|
||
|
url: '../previewWork/previewWork?path='+Path,
|
||
|
})
|
||
|
},
|
||
|
//预览素材
|
||
|
playingFodder: function () {
|
||
|
this.setData({
|
||
|
muted: false
|
||
|
})
|
||
|
this.videoContext.play();
|
||
|
|
||
|
},
|
||
|
//重新录音
|
||
|
reDub: function () {
|
||
|
myRecord.stop();
|
||
|
this.setData({
|
||
|
isSpeaking: false
|
||
|
});
|
||
|
wx.showModal({
|
||
|
title: '提示',
|
||
|
content: '重新录音'
|
||
|
});
|
||
|
this.startDub();
|
||
|
},
|
||
|
//结束录音
|
||
|
endDub() {
|
||
|
this.videoContext.stop();
|
||
|
myRecord.stop();
|
||
|
myRecord.onStop((res) => {
|
||
|
getApp().globalData.workPath = res.tempFilePath;
|
||
|
|
||
|
})
|
||
|
wx.navigateTo({
|
||
|
url: '../previewWork/previewWork?path=' + Path,
|
||
|
})
|
||
|
wx.showToast({
|
||
|
title: '录音结束',
|
||
|
icon: 'success',
|
||
|
duration: 200
|
||
|
})
|
||
|
},
|
||
|
|
||
|
// 开始录音,
|
||
|
startDub: function () {
|
||
|
this.videoContext.seek(0);
|
||
|
this.videoContext.play();
|
||
|
this.setData({
|
||
|
isSpeaking: true,
|
||
|
muted: true,
|
||
|
})
|
||
|
const options = {
|
||
|
//duration: 10000,//指定录音的时长,单位 ms
|
||
|
sampleRate: 16000,//采样率
|
||
|
numberOfChannels: 1,//录音通道数
|
||
|
encodeBitRate: 96000,//编码码率
|
||
|
format: 'mp3',//音频格式,有效值 aac/mp3
|
||
|
frameSize: 50,//指定帧大小,单位 KB
|
||
|
}
|
||
|
//开始录音
|
||
|
|
||
|
myRecord.start(options);
|
||
|
myRecord.onStart(() => {
|
||
|
// console.log('recorder start')
|
||
|
wx.showToast({
|
||
|
title: '录音成功',
|
||
|
duration: 200
|
||
|
})
|
||
|
});
|
||
|
//错误回调
|
||
|
myRecord.onError((res) => {
|
||
|
console.log(res);
|
||
|
wx.showToast({
|
||
|
title: '录音出错',
|
||
|
duration: 200
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
})
|