Пример #1
0
 protected void loadDanmakus(BaseDanmakuParser parser) {
   danmakuList = parser.setDisplayer(mDisp).setTimer(mTimer).getDanmakus();
   GlobalFlagValues.resetAll();
 }
Пример #2
0
  @Override
  public void handleMessage(Message msg) {
    int what = msg.what;
    switch (what) {
      case PREPARE:
        if (mParser == null || !mDanmakuView.isViewReady()) {
          sendEmptyMessageDelayed(PREPARE, 100);
        } else {
          prepare(
              new Runnable() {
                @Override
                public void run() {
                  mReady = true;
                  if (mCallback != null) {
                    mCallback.prepared();
                  }
                }
              });
        }
        break;
      case START:
        Long startTime = (Long) msg.obj;
        if (startTime != null) {
          pausedPostion = startTime.longValue();
        } else {
          pausedPostion = 0;
        }
      case RESUME:
        quitFlag = false;
        if (mReady) {
          mTimeBase = System.currentTimeMillis() - pausedPostion;
          timer.update(pausedPostion);
          removeMessages(RESUME);
          sendEmptyMessage(UPDATE);
          drawTask.start();
        } else {
          sendEmptyMessageDelayed(RESUME, 100);
        }
        break;
      case SEEK_POS:
        Long deltaMs = (Long) msg.obj;
        mTimeBase -= deltaMs;
        timer.update(System.currentTimeMillis() - mTimeBase);
        if (drawTask != null) drawTask.seek(timer.currMillisecond);
        pausedPostion = timer.currMillisecond;
        removeMessages(RESUME);
        sendEmptyMessage(RESUME);
        break;
      case UPDATE:
        if (quitFlag) {
          break;
        }
        long startMS = System.currentTimeMillis();
        long d = timer.update(startMS - mTimeBase);
        if (mCallback != null) {
          mCallback.updateTimer(timer);
        }
        if (d < 0) {
          removeMessages(UPDATE);
          sendEmptyMessageDelayed(UPDATE, 60 - d);
          break;
        }
        d = mDanmakuView.drawDanmakus();
        removeMessages(UPDATE);
        if (d == -1) {
          // reduce refresh rate
          sendEmptyMessageDelayed(UPDATE, 100);
          break;
        }

        if (d <= 16) {
          sendEmptyMessage(UPDATE);
          SystemClock.sleep(16 - d);
          break;
        }
        sendEmptyMessage(UPDATE);
        break;
      case SHOW_DANMAKUS:
        Long start = (Long) msg.obj;
        if (start == null && drawTask != null) {
          drawTask.requestClear();
        } else if (start != null && drawTask != null) {
          drawTask.start();
          drawTask.seek(start);
          drawTask.requestClear();
          obtainMessage(START, start).sendToTarget();
        }
        mDanmakusVisible = true;
        break;
      case HIDE_DANMAKUS:
        if (mDanmakuView != null) {
          mDanmakuView.clear();
        }
        Boolean quitDrawTask = (Boolean) msg.obj;
        if (quitDrawTask.booleanValue() && this.drawTask != null) {
          this.drawTask.quit();
        }
        mDanmakusVisible = false;
        if (!quitDrawTask) {
          break;
        }
      case PAUSE:
      case QUIT:
        removeCallbacksAndMessages(null);
        quitFlag = true;
        mDrawTimes.clear();
        pausedPostion = timer.currMillisecond;
        if (what == QUIT) {
          if (this.drawTask != null) {
            this.drawTask.quit();
          }
          if (this.getLooper() != Looper.getMainLooper()) this.getLooper().quit();

          if (mParser != null) {
            mParser.release();
          }
        }
        break;
    }
  }
Пример #3
0
 @Override
 public void handleMessage(Message msg) {
   int what = msg.what;
   switch (what) {
     case PREPARE:
       if (mParser == null || !mDanmakuView.isViewReady()) {
         sendEmptyMessageDelayed(PREPARE, 100);
       } else {
         prepare(
             new Runnable() {
               @Override
               public void run() {
                 mReady = true;
                 if (mCallback != null) {
                   mCallback.prepared();
                 }
               }
             });
       }
       break;
     case SHOW_DANMAKUS:
       mDanmakusVisible = true;
       Long start = (Long) msg.obj;
       boolean resume = false;
       if (drawTask != null) {
         if (start == null) {
           timer.update(getCurrentTime());
           drawTask.requestClear();
         } else {
           drawTask.start();
           drawTask.seek(start);
           drawTask.requestClear();
           resume = true;
         }
       }
       if (quitFlag && mDanmakuView != null) {
         mDanmakuView.drawDanmakus();
       }
       notifyRendering();
       if (!resume) {
         break;
       }
     case START:
       Long startTime = (Long) msg.obj;
       if (startTime != null) {
         pausedPosition = startTime;
       } else {
         pausedPosition = 0;
       }
     case RESUME:
       quitFlag = false;
       if (mReady) {
         mRenderingState.reset();
         mDrawTimes.clear();
         mTimeBase = SystemClock.uptimeMillis() - pausedPosition;
         timer.update(pausedPosition);
         removeMessages(RESUME);
         sendEmptyMessage(UPDATE);
         drawTask.start();
         notifyRendering();
         mInSeekingAction = false;
       } else {
         sendEmptyMessageDelayed(RESUME, 100);
       }
       break;
     case SEEK_POS:
       quitFlag = true;
       quitUpdateThread();
       Long position = (Long) msg.obj;
       long deltaMs = position - timer.currMillisecond;
       mTimeBase -= deltaMs;
       timer.update(SystemClock.uptimeMillis() - mTimeBase);
       mContext.mGlobalFlagValues.updateMeasureFlag();
       if (drawTask != null) drawTask.seek(timer.currMillisecond);
       pausedPosition = timer.currMillisecond;
       removeMessages(RESUME);
       sendEmptyMessage(RESUME);
       break;
     case UPDATE:
       if (mUpdateInNewThread) {
         updateInNewThread();
       } else {
         updateInCurrentThread();
       }
       break;
     case NOTIFY_DISP_SIZE_CHANGED:
       mContext.mDanmakuFactory.notifyDispSizeChanged(mContext);
       Boolean updateFlag = (Boolean) msg.obj;
       if (updateFlag != null && updateFlag) {
         mContext.mGlobalFlagValues.updateMeasureFlag();
       }
       break;
     case HIDE_DANMAKUS:
       mDanmakusVisible = false;
       if (mDanmakuView != null) {
         mDanmakuView.clear();
       }
       if (this.drawTask != null) {
         this.drawTask.requestClear();
         this.drawTask.requestHide();
       }
       Boolean quitDrawTask = (Boolean) msg.obj;
       if (quitDrawTask && this.drawTask != null) {
         this.drawTask.quit();
       }
       if (!quitDrawTask) {
         break;
       }
     case PAUSE:
       removeMessages(UPDATE);
     case QUIT:
       if (what == QUIT) {
         removeCallbacksAndMessages(null);
       }
       quitFlag = true;
       syncTimerIfNeeded();
       if (mThread != null) {
         notifyRendering();
         quitUpdateThread();
       }
       pausedPosition = timer.currMillisecond;
       if (what == QUIT) {
         if (this.drawTask != null) {
           this.drawTask.quit();
         }
         if (mParser != null) {
           mParser.release();
         }
         if (this.getLooper() != Looper.getMainLooper()) this.getLooper().quit();
       }
       break;
     case NOTIFY_RENDERING:
       notifyRendering();
       break;
     case UPDATE_WHEN_PAUSED:
       if (quitFlag && mDanmakuView != null) {
         drawTask.requestClear();
         mDanmakuView.drawDanmakus();
         notifyRendering();
       }
       break;
     case CLEAR_DANMAKUS_ON_SCREEN:
       if (drawTask != null) {
         drawTask.clearDanmakusOnScreen(getCurrentTime());
       }
       break;
   }
 }