123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- Page({
- data: {
- fullScreenBtn: false,
- playBtn: false,
- gesture: true,
- muted: true,
- gesture: false,
- centerBtn: false,
- recordFlag: 0,
- recordSource: '',
- videoCtr: 'recordingVideoEnd',
- },
- onLoad: function (option) {
- if (option.title) {
- wx.setNavigationBarTitle({
- title: option.title
- })
- }
- this.recorderManager = wx.getRecorderManager();
- this.videoCtx = wx.createVideoContext('myVideo', this);
-
-
- this.recorderManager.onStart(() => {
- this.videoCtx.play();
- this.setData({
- recordFlag: 1
- })
- console.log('recorder start')
- })
-
- this.recorderManager.onStop((res) => {
- this.videoCtx.stop();
- console.log('recorder stop', res)
- console.log(res.tempFilePath)
- const recordFile = res.tempFilePath;
- this.setData({
- recordFlag: 0,
- recordSource: recordFile
- })
- })
- },
-
-
-
-
- recordingVideoEnd:function(){
-
- if (this.data.recordFlag === 0) {
- this.recordStop();
- this.setData({
- videoCtr : 'playingVideoEnd'
- })
- }
-
- if (this.data.recordFlag === 1) {
-
- }
- },
-
- playingVideoEnd:function(){
- this.innerAudioContext.stop();
- },
-
- audioRecord: function () {
- console.log(this.data.recordFlag)
- if (this.data.recordFlag === 0) {
- this.recordStart();
- }
-
- if (this.data.recordFlag === 1) {
- this.recordStop();
- }
- },
-
-
- recordStart: function () {
- 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;
- this.videoCtx.play();
- this.innerAudioContext.play();
- },
- })
|