Commit 754a8ff874b6f427080420df71acb967dc3bcf07
1 parent
6b3ed290
fix audio play
Showing
3 changed files
with
67 additions
and
12 deletions
src/gxb-ide/Dir.js
| ... | ... | @@ -9,6 +9,8 @@ |
| 9 | 9 | fileList, // 有值的文件数据结构 |
| 10 | 10 | treeObj; // 获取ztree对象 |
| 11 | 11 | |
| 12 | + var playTimes = 0; | |
| 13 | + | |
| 12 | 14 | var playTreePathData = {"tree": []}; |
| 13 | 15 | |
| 14 | 16 | var isReplayPage = false; |
| ... | ... | @@ -612,8 +614,11 @@ |
| 612 | 614 | |
| 613 | 615 | var role = getQuery('role'); |
| 614 | 616 | if (role == 0) { |
| 615 | - // 请求玩立刻执行 | |
| 616 | - $.AudioPlayer.play() | |
| 617 | + if (playTimes === 0) { | |
| 618 | + // 请求玩立刻执行 | |
| 619 | + $.AudioPlayer.play() | |
| 620 | + playTimes++ | |
| 621 | + } | |
| 617 | 622 | }else{ |
| 618 | 623 | CodingEditer.playCoding(); |
| 619 | 624 | } |
| ... | ... | @@ -647,9 +652,21 @@ |
| 647 | 652 | imagePath: '../js/audioPlayer/image', |
| 648 | 653 | debuggers: false, |
| 649 | 654 | allowSeek: false, |
| 655 | + canplayCallback: function(res){ | |
| 656 | + if (res.status == true) { | |
| 657 | + CodingEditer.playCoding(); | |
| 658 | + } | |
| 659 | + }, | |
| 660 | + onwaitingCallback: function(){ | |
| 661 | + if (playTimes != 0) { | |
| 662 | + CodingEditer.audioTime = parseInt(player.elements.audioDom.currentTime*1000); | |
| 663 | + CodingEditer.pauseCode(); | |
| 664 | + } | |
| 665 | + }, | |
| 650 | 666 | playCallback: function() { // 播放 |
| 651 | - console.log('++++++++'); | |
| 652 | - CodingEditer.playCoding(); | |
| 667 | + if (playTimes != 0) { | |
| 668 | + CodingEditer.playCoding(); | |
| 669 | + } | |
| 653 | 670 | }, |
| 654 | 671 | pauseCallback: function() { // 暂停 |
| 655 | 672 | CodingEditer.audioTime = parseInt(player.elements.audioDom.currentTime*1000); | ... | ... |
src/js/audioPlayer/jQuery.AudioPlayer.js
100755 → 100644
| ... | ... | @@ -2,8 +2,8 @@ |
| 2 | 2 | * jQuery.AudioPlayer.js |
| 3 | 3 | * @Author Keystion |
| 4 | 4 | * @Version 1.0.1 |
| 5 | - * Created by Keystion on 2016-12-19 | |
| 6 | - * Update on 2017-01-06 | |
| 5 | + * Created by Keystion on 2016-12-19. Update on 2017-01-06 | |
| 6 | + * https://github.com/Keystion/jQuery.AudioPlayer.js | |
| 7 | 7 | */ |
| 8 | 8 | ;(function(jQuery){ |
| 9 | 9 | "use strict"; |
| ... | ... | @@ -11,24 +11,31 @@ |
| 11 | 11 | options: { |
| 12 | 12 | // open console log / 打开控制台日志 |
| 13 | 13 | debuggers: false |
| 14 | - // container, default 'body' / 组件要放到什么地方,默认'body' | |
| 14 | + // The outer Dom ClassName/id, default 'body' | |
| 15 | + // 外部Dom ClassName / id,默认的“body” | |
| 15 | 16 | ,container: 'body' |
| 16 | 17 | // audio source / 音频源 |
| 17 | 18 | ,source: '' |
| 18 | - // 音频源文件 / image resources | |
| 19 | + // image resources / 图像资源 | |
| 19 | 20 | ,imagePath: './image' |
| 20 | 21 | // Determines whether or not the player is playing before dragging/判断拖拽之前是否正在播放 |
| 21 | 22 | ,seekNum: 0 |
| 22 | - // Whether can drag and drop / 是否可以拖拽 | |
| 23 | + // Whether to support drag and drop, the default open: `true` / 是否支持拖拽,默认开启:`true` | |
| 23 | 24 | ,allowSeek: true |
| 24 | 25 | // After can play TODO / 可以播放之后,做某些事情 |
| 25 | 26 | ,canplayCallback: null |
| 27 | + // After searching for the audio TODO / 开始查找音频源之后,做某些事情 | |
| 28 | + ,onloadstartCallback: null | |
| 29 | + // 需要缓冲下一帧而停止,做某些事情 | |
| 30 | + ,onwaitingCallback: null | |
| 26 | 31 | // After playback TODO / 播放之后,做某些事情 |
| 27 | 32 | ,playCallback: null |
| 28 | 33 | // After the suspension TODO / 暂停之后,做某些事情 |
| 29 | 34 | ,pauseCallback: null |
| 30 | 35 | // After the drag TODO / 拖动之后,做某些事情 |
| 31 | 36 | ,timeupdateCallback: null |
| 37 | + // After the drag, the callback function (`allowSeek: false`) / 拖动之后,回调函数(`allowSeek: false`) | |
| 38 | + ,seekedCallback: null | |
| 32 | 39 | // End of the play TODO / 播放结束之后,做某些事情 |
| 33 | 40 | ,endedCallback: null |
| 34 | 41 | // After the mute TODO / 静音之后,做某些事情 |
| ... | ... | @@ -258,6 +265,9 @@ |
| 258 | 265 | // When the browser begins searching for the audio / 当浏览器开始查找音频时 |
| 259 | 266 | _this.elements.audioDom.onloadstart = function() { |
| 260 | 267 | _this.log('onloadstart'); |
| 268 | + if(typeof _this.options.onloadstartCallback == 'function'){ | |
| 269 | + _this.options.onloadstartCallback({'status': true}); | |
| 270 | + } | |
| 261 | 271 | } |
| 262 | 272 | |
| 263 | 273 | // When the audio has begun or is no longer suspended / 当音频已开始或不再暂停时 |
| ... | ... | @@ -300,6 +310,13 @@ |
| 300 | 310 | _this.timeupdate(); |
| 301 | 311 | } |
| 302 | 312 | |
| 313 | + _this.elements.audioDom.onwaiting = function() { | |
| 314 | + _this.log('onwaiting'); | |
| 315 | + if(typeof _this.options.onwaitingCallback == 'function'){ | |
| 316 | + _this.options.onwaitingCallback({'status': true}); | |
| 317 | + } | |
| 318 | + } | |
| 319 | + | |
| 303 | 320 | // When the volume is changed |
| 304 | 321 | // 当音量已更改时 |
| 305 | 322 | _this.elements.audioDom.onvolumechange = function() { | ... | ... |
src/js/gbreplayer.js
| ... | ... | @@ -80,6 +80,7 @@ $(function(){ |
| 80 | 80 | times: 0, // 播放次数 |
| 81 | 81 | isPause: 1, // 是否暂停 1:不暂停,0:暂停 |
| 82 | 82 | isRcording: 0, // 是否录制 1:录制中,0:暂停中 |
| 83 | + playTimes: 0, | |
| 83 | 84 | recordinit: function(codereplaytype, preload) { |
| 84 | 85 | var modeName = getMode(_languageid); |
| 85 | 86 | var modeNameItem = modeName[0]; |
| ... | ... | @@ -428,9 +429,26 @@ $(function(){ |
| 428 | 429 | ,imagePath: 'js/audioPlayer/image' |
| 429 | 430 | ,debuggers: false |
| 430 | 431 | ,allowSeek: false |
| 432 | + ,canplayCallback: function(res){ | |
| 433 | + if (res.status == true) { | |
| 434 | + playCode(); | |
| 435 | + GBCodePlayBack.htmlplayereditor.setOption('readOnly', true); | |
| 436 | + } | |
| 437 | + } | |
| 438 | + ,onwaitingCallback: function(){ | |
| 439 | + if (GBCodePlayBack.playTimes !== 0) { | |
| 440 | + GBCodePlayBack.audioTime = parseInt(player.elements.audioDom.currentTime*1000) | |
| 441 | + pauseCode(); | |
| 442 | + GBCodePlayBack.firstPlay = 0; | |
| 443 | + GBCodePlayBack.pauseValue = GBCodePlayBack.htmlplayereditor.getValue(); | |
| 444 | + GBCodePlayBack.htmlplayereditor.setOption('readOnly', false); | |
| 445 | + } | |
| 446 | + } | |
| 431 | 447 | ,playCallback: function(){ // 播放 |
| 432 | - playCode(); | |
| 433 | - GBCodePlayBack.htmlplayereditor.setOption('readOnly', true); | |
| 448 | + if (GBCodePlayBack.playTimes != 0) { | |
| 449 | + playCode(); | |
| 450 | + GBCodePlayBack.htmlplayereditor.setOption('readOnly', true); | |
| 451 | + } | |
| 434 | 452 | } |
| 435 | 453 | ,pauseCallback: function(){ // 暂停 |
| 436 | 454 | GBCodePlayBack.audioTime = parseInt(player.elements.audioDom.currentTime*1000) |
| ... | ... | @@ -462,7 +480,10 @@ $(function(){ |
| 462 | 480 | } |
| 463 | 481 | |
| 464 | 482 | GBCodePlayBack.records = coderecords; |
| 465 | - player.play(); | |
| 483 | + if(GBCodePlayBack.playTimes === 0){ | |
| 484 | + player.play(); | |
| 485 | + GBCodePlayBack.playTimes++ | |
| 486 | + } | |
| 466 | 487 | } |
| 467 | 488 | |
| 468 | 489 | // 使编辑器满屏 | ... | ... |