Commit 6963a3f3d8b71e0e9a1ebb9726ec6ea105bd43eb

Authored by 商艳涛
1 parent 4795b643

修复浏览器无法自动播放语音

dist/gxb-ide/CodingEditer.js
... ... @@ -121,7 +121,7 @@
121 121 * 播放代码
122 122 * Created by Kira on 2017-02-08
123 123 */
124   - playCoding: function(){
  124 + playCoding: function(e){
125 125 CodingEditer.editable(1);
126 126 CodingEditer.flag = false;
127 127 if (CodingEditer.firstPlay == 0) {
... ... @@ -145,30 +145,36 @@
145 145 var playTotalTime = 0;
146 146  
147 147 $('#recordertab a:eq(1)').tab('show');
  148 + // 处理浏览器无法自动播放语音时候,编辑器显示空内容
  149 + if (e && !e.status) {
  150 + var timeoutcontroller = null;
  151 + CodingEditer.recordtimeoutcontrolls.push(timeoutcontroller);
  152 + } else {
  153 + for (var i = 0; i < playbackrecord.length; i++) {
  154 + if (playbackrecord[i].trigger === 1) {
  155 + playTotalTime += parseInt(playbackrecord[i].intervaltime);
  156 + }else if (playbackrecord[i].trigger === 0) {
  157 + var timeoutcontroller = null;
  158 + var replayinterval = playbackrecord[i].intervaltime;
  159 +
  160 + if (!CodingEditer.isPause) {
  161 + starttime = replayinterval - (CodingEditer.audioTime - playTotalTime);
  162 + CodingEditer.isPause = true;
  163 + }else{
  164 + // if (i == 0) {
  165 + // starttime = replayinterval;
  166 + // }else{
  167 + // starttime = parseInt(starttime) + parseInt(replayinterval);
  168 + // }
  169 + starttime = parseInt(starttime) + parseInt(replayinterval);
  170 + }
148 171  
149   - for (var i = 0; i < playbackrecord.length; i++) {
150   - if (playbackrecord[i].trigger === 1) {
151   - playTotalTime += parseInt(playbackrecord[i].intervaltime);
152   - }else if (playbackrecord[i].trigger === 0) {
153   - var timeoutcontroller = null;
154   - var replayinterval = playbackrecord[i].intervaltime;
155   -
156   - if (!CodingEditer.isPause) {
157   - starttime = replayinterval - (CodingEditer.audioTime - playTotalTime);
158   - CodingEditer.isPause = true;
159   - }else{
160   - // if (i == 0) {
161   - // starttime = replayinterval;
162   - // }else{
163   - // starttime = parseInt(starttime) + parseInt(replayinterval);
164   - // }
165   - starttime = parseInt(starttime) + parseInt(replayinterval);
  172 + timeoutcontroller = setTimeout(changeValueCallback(playbackrecord[i]), starttime/CodingEditer.speed);
  173 + CodingEditer.recordtimeoutcontrolls.push(timeoutcontroller);
166 174 }
167   -
168   - timeoutcontroller = setTimeout(changeValueCallback(playbackrecord[i]), starttime/CodingEditer.speed);
169   - CodingEditer.recordtimeoutcontrolls.push(timeoutcontroller);
170 175 }
171 176 }
  177 +
172 178 console.log(CodingEditer.recordtimeoutcontrolls)
173 179 },
174 180 pauseCode: function(){
... ...
dist/gxb-ide/Dir.js
... ... @@ -782,23 +782,9 @@
782 782 imagePath: '../js/audioPlayer/image',
783 783 debuggers: false,
784 784 allowSeek: false,
785   - canplayCallback: function(res){
786   - if (res.status == true && playTimes === 0 && !isAndroid) {
787   - CodingEditer.playCoding();
788   - playTimes++
789   - // alert('canplay !isAndroid ----------- ' + playTimes)
790   - }
791   - // alert('canplayCallback可以播放 ----------- ' + playTimes)
792   - },
793   - onwaitingCallback: function(){
794   - // alert('onwaitingCallback ----------- ' + playTimes)
795   - },
796   - playCallback: function() { // 播放
797   - if (playTimes != 0) {
798   - CodingEditer.playCoding();
799   - // alert('playCoding可以播放 ----------- ' + playTimes)
800   - }
801   - // alert('playCoding可以播放 ----------- ' + playTimes)
  785 + playCallback: function(e) { // 播放
  786 + console.log('++++++++');
  787 + CodingEditer.playCoding(e);
802 788 },
803 789 pauseCallback: function() { // 暂停
804 790 CodingEditer.audioTime = parseInt(player.elements.audioDom.currentTime*1000);
... ...
dist/js/audioPlayer/jQuery.AudioPlayer.js
... ... @@ -352,13 +352,20 @@
352 352 // Set the playback / 设置播放
353 353 ,play: function(o) {
354 354 var _this = this;
355   - _this.elements.audioDom.play();
356   - if (typeof o == 'function') {
357   - o({'status': _this.elements.audioDom.play});
358   - }
  355 + var canPlay = _this.elements.audioDom.play();
  356 + // 处理浏览器无法自动播放语音
  357 + if (canPlay !== undefined) {
  358 + canPlay.then(_ => {
  359 + if (typeof o == 'function') {
  360 + o({'status': true});
  361 + }
359 362  
360   - if(typeof _this.options.playCallback == 'function'){
361   - _this.options.playCallback({'status': _this.elements.audioDom.play});
  363 + if(typeof _this.options.playCallback == 'function'){
  364 + _this.options.playCallback({'status': true});
  365 + }
  366 + }).catch(error => {
  367 + _this.options.playCallback({'status': false});
  368 + });
362 369 }
363 370 }
364 371 // Set the suspend / 设置暂停
... ...