Page({ data: { fullScreenBtn: false, playBtn: false, gesture: true, muted: true, gesture: false, centerBtn: false, recordFlag: 0, recordSource: '', videoCtr: 'recordingVideoEnd', btnFlag: false, microphonePng: '../../../static/image/microphone.png', recordingGif: '../../../static/image/readingNow.gif', videoUrl:'http://efunvideo.ai160.com/vs2m/001/00103075/00103075012/00103075012.m3u8', readingText: '江南好,\n风景旧曾谙。\n日出江花红胜火,\n春来江水绿如蓝。\n能不忆江南?\n江南好\n江南好,\n风景旧曾谙。\n日出江花红胜火,\n春来江水绿如蓝。\n能不忆江南?\n江南好\n江南好,\n风景旧曾谙。\n日出江花红胜火,\n春来江水绿如蓝。\n能不忆江南?\n江南好\n江南好,\n风景旧曾谙。\n日出江花红胜火,\n春来江水绿如蓝。\n能不忆江南?\n江南好\n江南好,\n风景旧曾谙。\n日出江花红胜火,\n春来江水绿如蓝。\n能不忆江南?\n' }, onLoad: function (option) { this.videoCtx = null; if (option.title) { wx.setNavigationBarTitle({ title: option.title //页面标题为路由参数 }) } this.recorderManager = wx.getRecorderManager(); // 监听录音部分 // 录音开始 this.recorderManager.onStart(() => { // this.saveVideo(); console.log('recorder start') }) // 录音结束 this.recorderManager.onStop((res) => { this.videoCtx.stop(); console.log('recorder stop', res) const recordFile = res.tempFilePath; this.setData({ recordFlag: 0, recordSource: recordFile, btnFlag: true }) }) }, // onShow:function(){ // }, // 录音中视频播放结束 (控制录音同时结束) recordingVideoEnd:function(){ // if (this.data.recordFlag === 0) { this.recordStop(); this.setData({ videoCtr : 'playingVideoEnd' }) } // 录音结束 if (this.data.recordFlag === 1) { // this.recordStop(); } }, // 播放中视频播放结束 (控制录音同时结束) playingVideoEnd:function(){ this.innerAudioContext.stop(); }, /*** * recordFlag: * 0 初始状态 * 1 录音中 ***/ audioRecord: function () { console.log(this.data.recordFlag) if (this.data.recordFlag === 0) { // this.recordStart(); // this.saveVideo(); this.videoComplete(); } // 录音结束后 if (this.data.recordFlag === 1) { this.recordStop(); } }, // 录音开始 /** * duration: 时长 最长10分钟 sampleRate: 44100, 采样率 numberOfChannels: 1, 录音通道 encodeBitRate: 192000, 码率 format: 'mp3', 格式 frameSize: 50 制定帧大小 */ recordStart: function () { console.log('录音开始'); const options = { duration: 600000, sampleRate: 44100, numberOfChannels: 1, encodeBitRate: 192000, format: 'mp3', frameSize: 50 } this.recorderManager.start(options); }, // 录音结束 recordStop: function () { this.recorderManager.stop(); }, // 播放录音 audioPlay: function () { console.log('音频播放'); this.innerAudioContext = wx.createInnerAudioContext(); this.innerAudioContext.onError((res) => { // 播放音频失败的回调 }) this.innerAudioContext.src = this.data.recordSource; // 这里可以是录音的临时路径 console.log(this.innerAudioContext.src); this.videoCtx.play(); this.innerAudioContext.play(); }, videoComplete: function(){ let videoUrl = 'http://efunimgs.ai160.com/ott/test/002tPr2Xlx07oP7B4ro40104120022hP0k010.mp4'; this.setData({ videoUrl: videoUrl, recordFlag: 1 },()=>{ this.videoCtx = wx.createVideoContext('myVideo', this); this.videoCtx.play(); this.recordStart(); }) } })