reading.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. Page({
  2. data: {
  3. fullScreenBtn: false,
  4. playBtn: false,
  5. gesture: true,
  6. muted: true,
  7. gesture: false,
  8. centerBtn: false,
  9. recordFlag: 0,
  10. recordSource: '',
  11. videoCtr: 'recordingVideoEnd',
  12. btnFlag: false,
  13. microphonePng: '../../../static/image/microphone.png',
  14. recordingGif: '../../../static/image/readingNow.gif',
  15. videoUrl:'http://efunvideo.ai160.com/vs2m/001/00103075/00103075012/00103075012.m3u8',
  16. 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'
  17. },
  18. onLoad: function (option) {
  19. this.videoCtx = null;
  20. if (option.title) {
  21. wx.setNavigationBarTitle({
  22. title: option.title //页面标题为路由参数
  23. })
  24. }
  25. this.recorderManager = wx.getRecorderManager();
  26. // 监听录音部分
  27. // 录音开始
  28. this.recorderManager.onStart(() => {
  29. // this.saveVideo();
  30. console.log('recorder start')
  31. })
  32. // 录音结束
  33. this.recorderManager.onStop((res) => {
  34. this.videoCtx.stop();
  35. console.log('recorder stop', res)
  36. const recordFile = res.tempFilePath;
  37. this.setData({
  38. recordFlag: 0,
  39. recordSource: recordFile,
  40. btnFlag: true
  41. })
  42. })
  43. },
  44. // onShow:function(){
  45. // },
  46. // 录音中视频播放结束 (控制录音同时结束)
  47. recordingVideoEnd:function(){
  48. //
  49. if (this.data.recordFlag === 0) {
  50. this.recordStop();
  51. this.setData({
  52. videoCtr : 'playingVideoEnd'
  53. })
  54. }
  55. // 录音结束
  56. if (this.data.recordFlag === 1) {
  57. // this.recordStop();
  58. }
  59. },
  60. // 播放中视频播放结束 (控制录音同时结束)
  61. playingVideoEnd:function(){
  62. this.innerAudioContext.stop();
  63. },
  64. /***
  65. * recordFlag:
  66. * 0 初始状态
  67. * 1 录音中
  68. ***/
  69. audioRecord: function () {
  70. console.log(this.data.recordFlag)
  71. if (this.data.recordFlag === 0) {
  72. // this.recordStart();
  73. // this.saveVideo();
  74. this.videoComplete();
  75. }
  76. // 录音结束后
  77. if (this.data.recordFlag === 1) {
  78. this.recordStop();
  79. }
  80. },
  81. // 录音开始
  82. /**
  83. * duration: 时长 最长10分钟
  84. sampleRate: 44100, 采样率
  85. numberOfChannels: 1, 录音通道
  86. encodeBitRate: 192000, 码率
  87. format: 'mp3', 格式
  88. frameSize: 50 制定帧大小
  89. */
  90. recordStart: function () {
  91. console.log('录音开始');
  92. const options = {
  93. duration: 600000,
  94. sampleRate: 44100,
  95. numberOfChannels: 1,
  96. encodeBitRate: 192000,
  97. format: 'mp3',
  98. frameSize: 50
  99. }
  100. this.recorderManager.start(options);
  101. },
  102. // 录音结束
  103. recordStop: function () {
  104. this.recorderManager.stop();
  105. },
  106. // 播放录音
  107. audioPlay: function () {
  108. console.log('音频播放');
  109. this.innerAudioContext = wx.createInnerAudioContext();
  110. this.innerAudioContext.onError((res) => {
  111. // 播放音频失败的回调
  112. })
  113. this.innerAudioContext.src = this.data.recordSource; // 这里可以是录音的临时路径
  114. console.log(this.innerAudioContext.src);
  115. this.videoCtx.play();
  116. this.innerAudioContext.play();
  117. },
  118. videoComplete: function(){
  119. let videoUrl = 'http://efunimgs.ai160.com/ott/test/002tPr2Xlx07oP7B4ro40104120022hP0k010.mp4';
  120. this.setData({
  121. videoUrl: videoUrl,
  122. recordFlag: 1
  123. },()=>{
  124. this.videoCtx = wx.createVideoContext('myVideo', this);
  125. this.videoCtx.play();
  126. this.recordStart();
  127. })
  128. }
  129. })