123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- import httpRequestApi from '../../../utils/APIClient';
- Page({
- data: {
- title: '',
- id: '',
- img: '',
- fullScreenBtn: false,
- playBtn: false,
- gesture: true,
- muted: true,
- gesture: false,
- centerBtn: false,
- recordFlag: 0,
- recordSource: '',
- videoCtr: 'recordingVideoEnd',
- btnFlag: false,
- btnImgFlag: false,
- microphonePng: '../../../static/image/microphone.png',
- recordingGif: '../../../static/image/readingNow.gif',
- videoUrl: '',
- readingText: ''
- },
- onLoad: function (option) {
- console.log(option);
- this.videoCtx = null;
- const uid = wx.getStorageSync('uid')
- httpRequestApi.getClassDetail(uid, option.id).success(res => {
- let reg = /\\n/g
- this.setData({
- title: res.data.data.title,
- videoUrl: res.data.data.playUrl,
- img: res.data.data.iconImg,
- id: res.data.data.id,
-
- readingText: res.data.data.lessonText,
- grade: res.data.data.gradeClassify
- })
- console.log(this.data.readingText)
- console.log(this.data.img)
- }, () => {
- wx.setNavigationBarTitle({
- title: this.data.title
- })
- })
- this.recorderManager = wx.getRecorderManager();
-
-
- this.recorderManager.onStart(() => {
-
- this.setData({
- btnImgFlag: true
- })
- 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,
- btnImgFlag: false
- })
- })
- },
- onHide: function(){
- if(this.innerAudioContext){
- this.innerAudioContext.stop();
- }
- },
- onUnload: function(){
- if(this.innerAudioContext){
- this.innerAudioContext.stop();
- }
- },
-
-
-
- recordingVideoEnd: function () {
- console.log(this.data.videoCtr)
- console.log('recordingVideoEnd');
-
- if (this.data.recordFlag === 0) {
-
-
- this.playingVideoEnd();
- return;
- }
-
- if (this.data.recordFlag === 1) {
- this.recordStop();
- }
- },
-
- playingVideoEnd: function () {
- console.log('playingVideoEnd')
- this.innerAudioContext.stop();
- },
-
- audioRecord: function () {
- console.log(this.data.recordFlag)
- if (this.data.recordFlag === 0) {
-
-
- this.videoComplete();
- return;
- }
-
- if (this.data.recordFlag === 1) {
- wx.showLoading({
- title: '作品转码中',
- mask: true
- })
- this.recordStop();
- }
- },
-
-
- recordStart: function () {
- console.log('录音开始');
- const options = {
- duration: 600000,
- sampleRate: 44100,
- numberOfChannels: 1,
- encodeBitRate: 192000,
- format: 'mp3',
- frameSize: 50
- }
- this.recorderManager.start(options);
- },
-
- recordStop: function () {
- console.log('录音结束')
- this.recorderManager.stop();
- wx.hideLoading()
- },
-
- 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 () {
-
- this.setData({
- recordFlag: 1
- }, () => {
- this.videoCtx = wx.createVideoContext('myVideo', this);
- this.videoCtx.play();
- this.recordStart();
- })
- },
-
- upload: function () {
- wx.showLoading({
- title: '作品分享中',
- mask: true
- })
- const recordSource = this.data.recordSource;
- wx.uploadFile({
- url: 'https://readerbase.efunbox.cn/file/upload',
- filePath: recordSource,
- name: '朗读录音',
- header: {
- uid: wx.getStorageSync('uid')
- },
- success: (res) => {
- const formateRes = JSON.parse(res.data);
- let audioPath = formateRes.data;
- let uid = wx.getStorageSync('uid');
- shareWorks(uid, audioPath);
- }
- })
- let shareWorks = (uid, audio) => {
- console.log(this.data.img)
- const data = {
- "lessonId": this.data.id,
- "originVideo": this.data.videoUrl,
- "audioPath": audio,
- "title": this.data.title,
- "iconImg": this.data.img,
- "summary": this.data.grade,
- };
- httpRequestApi.postWork(uid, data).success(res => {
- wx.hideLoading({
- success: ()=>{
- wx.showToast({
- title: '上传成功',
- icon: 'success',
- duration: 1000,
- success: ()=>{
- console.log(res);
- wx.navigateTo({
- url: `../../social/works/works?id=${res.data.data.id}`
- })
- }
- })
- }
- });
-
- })
- };
- }
- })
|