李勇

1.增加计时器

  1 +// //////////////////////////////////////////////////////////////////////////////
  2 +// 计时器
  3 +// //////////////////////////////////////////////////////////////////////////////
  4 +
  5 +//import ApeConsts from './ApeConsts';
  6 +//import Loger from 'Loger';
  7 +//import MessageTypes from 'MessageTypes';
  8 +//import GlobalConfig from 'GlobalConfig';
  9 +//import EngineUtils from 'EngineUtils';
  10 +
  11 +//let loger = Loger.getLoger('MediaModule');
  12 +
  13 +let counter=0;
  14 +let callBackDelay=1;
  15 +let callBackFun;
  16 +let isStart=false;
  17 +class TimerCounter {
  18 + constructor() {
  19 + this.timer=0;
  20 + this.delay=1000;
  21 + }
  22 +
  23 + addTimerCallBack(_callBackFun,_callBackDelay){
  24 + callBackFun=_callBackFun;
  25 + callBackDelay=_callBackDelay;
  26 + }
  27 + //开计时
  28 + startTimer(_position=0) {
  29 + if(isStart) return;
  30 + isStart=true;
  31 + if(_position&&parseInt(_position)>0){
  32 + counter=_position;
  33 + }else {
  34 + counter=0;
  35 + }
  36 + console.log("startTimer",counter);
  37 + this.timerClear();
  38 + this.timerStart();
  39 +
  40 + }
  41 + //停止
  42 + stopTimer(){
  43 + console.log("stopTimer",counter);
  44 + isStart=false;
  45 + this.timerClear();
  46 + }
  47 + //计数
  48 + updateCounter(){
  49 + counter++;
  50 + //this.counter++;
  51 + //console.log("TimerCounter",counter);
  52 + if(callBackFun!=null&&counter%callBackDelay==0){
  53 + callBackFun();
  54 + }
  55 + }
  56 + timerStart(){
  57 + this.timer= setInterval(this.updateCounter, this.delay);
  58 + }
  59 + timerClear(){
  60 + clearInterval(this.timer);
  61 + }
  62 +}
  63 +export default TimerCounter;
  64 +