Commit 2f032f47f54ee972a1812a9fc900843b142af20d

Authored by ykxie
1 parent 93e794b6

暂停播放

Showing 1 changed file with 80 additions and 20 deletions
src/js/gbreplayer.js
... ... @@ -38,6 +38,8 @@ $(function(){
38 38 isgblibreplay: 0,
39 39 continue_recording: 0, //是否继续自动保`存的录制
40 40 recording_status: 1, //当前是否在录制
  41 + times: 0, // 播放次数
  42 + isPause: 1, // 是否暂停 1:不暂停,0:暂停
41 43 recordinit: function(codereplaytype, preload) {
42 44 /* #STRAT:生成CodeMirror Editor for JS/CSS/HTML */
43 45 var htmlid = document.getElementById('HTMLeditor'),
... ... @@ -385,26 +387,26 @@ $(function(){
385 387 ,debuggers: false
386 388 ,allowSeek: false
387 389 ,playCallback: function(){ // 播放
388   - if (GBCodePlayBack.firstPlay == 0) {
389   - $('#readonly').trigger('click');
390   - GBCodePlayBack.htmlplayereditor.setValue(GBCodePlayBack.pauseValue)
391   - }else{
392   - GBCodePlayBack.htmlplayereditor.setValue('')
393   - var resultData = {
394   - output: '',
395   - stderr: '',
396   - cmpinfo: '',
397   - result: 1
398   - };
399   - compileResult(resultData);
400   - }
401   -
402   - playCoder();
  390 + playCode();
  391 +
  392 + // if (GBCodePlayBack.firstPlay == 0) {
  393 + // $('#readonly').trigger('click');
  394 + // GBCodePlayBack.htmlplayereditor.setValue(GBCodePlayBack.pauseValue)
  395 + // }else{
  396 + // GBCodePlayBack.htmlplayereditor.setValue('')
  397 + // var resultData = {
  398 + // output: '',
  399 + // stderr: '',
  400 + // cmpinfo: '',
  401 + // result: 1
  402 + // };
  403 + // compileResult(resultData);
  404 + // }
  405 +
  406 + // playCoder();
403 407 // $('#play').trigger('click');
404 408 }
405   - ,pauseCallback: function(){ // 暂停
406   -
407   - GBCodePlayBack.pauseTime = new Date().getTime(); // 暂停的时间
  409 + ,pauseCallback: function(){ // 暂停
408 410  
409 411 $('#readonly').trigger('click');
410 412  
... ... @@ -413,8 +415,8 @@ $(function(){
413 415 GBCodePlayBack.pauseValue = GBCodePlayBack.htmlplayereditor.getValue();
414 416  
415 417 // $('#play').trigger('click');
416   - playCoder();
417   -
  418 + // playCoder();
  419 + pauseCode();
418 420 }
419 421 ,seekedCallback: function(){} // 拖拽
420 422 ,endedCallback: function(){ // 结束播放
... ... @@ -1397,6 +1399,7 @@ $(function(){
1397 1399  
1398 1400 record.trigger = 1; //标记已运行
1399 1401 record.playTime = new Date().getTime(); // 播放开始时间
  1402 + GBCodePlayBack.codeTimes = 1; //
1400 1403  
1401 1404 var resultData = {
1402 1405 output: record.output || '',
... ... @@ -1817,7 +1820,64 @@ $(function(){
1817 1820 $('#play').data('status', !playstatus);
1818 1821 }
1819 1822  
  1823 + function playCode(){
  1824 + // GBCodePlayBack.htmlplayereditor.setValue('')
  1825 + var playbackrecord = GBCodePlayBack.records;
  1826 + var starttime = 0;
  1827 + var stopIntervalTime;
  1828 +
  1829 + console.log(playbackrecord)
  1830 + for (var i = 0; i < playbackrecord.length; i++) {
  1831 + if (playbackrecord[i].trigger === 0) {
  1832 + var timeoutcontroller = null;
  1833 + var replayinterval = playbackrecord[i].intervaltime;
  1834 +
  1835 + if (!GBCodePlayBack.isPause) {
  1836 + if (i === 0) {
  1837 + // 暂停后重制 intervaltime
  1838 + stopIntervalTime = GBCodePlayBack.pauseTime - GBCodePlayBack.playRecordStart;
  1839 + playbackrecord[i].intervaltime = playbackrecord[i].intervaltime - stopIntervalTime;
  1840 + starttime = playbackrecord[i].intervaltime;
  1841 + }else{
  1842 + // 已有播放的代码
  1843 + GBCodePlayBack.stopIntervalTime = GBCodePlayBack.pauseTime - playbackrecord[i - 1].playTime;
  1844 + playbackrecord[i].intervaltime = playbackrecord[i].intervaltime - GBCodePlayBack.stopIntervalTime;
  1845 + starttime = playbackrecord[i].intervaltime;
  1846 + }
  1847 + GBCodePlayBack.isPause = 1
  1848 + }else{
  1849 + if (i == 0) {
  1850 + starttime = replayinterval;
  1851 + }else{
  1852 + starttime = parseInt(starttime) + parseInt(replayinterval);
  1853 + }
  1854 + }
  1855 + console.log(starttime);
  1856 + timeoutcontroller = setTimeout(GBCodePlayBack.changeValueCallback(playbackrecord[i]), starttime/GBCodePlayBack.speed);
  1857 + GBCodePlayBack.recordtimeoutcontrolls.push(timeoutcontroller);
  1858 + }
  1859 + }
  1860 + console.log(GBCodePlayBack.recordtimeoutcontrolls);
  1861 + // 记录播放的时间
  1862 + GBCodePlayBack.playRecordStart = new Date().getTime();
  1863 +
  1864 + }
  1865 +
  1866 + function pauseCode(){
  1867 + var recordtimeoutcontrolls = GBCodePlayBack.recordtimeoutcontrolls;
  1868 + GBCodePlayBack.isPause = 0;
  1869 +
  1870 + for (var i = 0; i < recordtimeoutcontrolls.length; i++) {
  1871 + clearTimeout(recordtimeoutcontrolls[i]);
  1872 + }
  1873 + GBCodePlayBack.recordtimeoutcontrolls = [];
  1874 + GBCodePlayBack.recordtimeouts = [];
  1875 +
  1876 + // 每次暂停的时间
  1877 + GBCodePlayBack.pauseTime = new Date().getTime();
1820 1878  
  1879 + console.log(GBCodePlayBack.pauseTime)
  1880 + }
1821 1881  
1822 1882  
1823 1883 var htmlhlLine = null,
... ...