/** 再生を停止する */
  public void stop() {
    if (C.LOCAL_LOG) {
      Log.v(C.TAG, "trying to stop playing.");
    }

    mPlayState.stop();
  }
  /**
   * 再生を開始する
   *
   * @param path 再生する音声のパス
   * @param notificationTitle Notificationに表示するタイトル。局名や番組名などを入れる。
   * @param notificationContent Notificationに表示するタイトル。アーティスト名などを入れる。
   */
  private void play(String path, String notificationTitle, String notificationContent) {
    if (C.LOCAL_LOG) {
      Log.v(C.TAG, "trying to play " + path + ".");
    }

    if (path == null) {
      notifyPlayStateChanged(MSG_MEDIA_PLAY_SERVICE_FAILD_PLAY_START);
      return;
    }

    synchronized (mLock) {
      if (mMediaPlayer == null) {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnCompletionListener(
            new OnCompletionListener() {
              @Override
              public void onCompletion(MediaPlayer mp) {
                synchronized (mLock) {
                  mp.stop();
                  mp.setOnPreparedListener(null);
                  mPlayingPath = null;
                  mNotificationTitle = null;
                  mNotificationContent = null;
                  mp.reset();
                }
                notifyPlayStateChanged(MSG_MEDIA_PLAY_SERVICE_PLAY_COMPLATED);

                changeState(new IdleState());
              }
            });
      }
    }

    mPlayState.play(path, notificationTitle, notificationContent);
  }
Пример #3
0
 @Override
 public void paintComponent(Graphics g) {
   Graphics2D g2d = (Graphics2D) g;
   super.paintComponent(g2d);
   g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (level < MAX_LEVEL) {
     g2d.drawImage(ground, 0, 0, Game.WIDTH, Game.HEIGHT2, null);
     g2d.drawImage(barbg, 250, Game.HEIGHT, 500, 100, null);
     play.draw(g2d);
     if (numDonuts < MAX_DONUTS) {
       g2d.setFont(font.deriveFont(30f));
       g2d.setColor(Color.BLACK);
       g2d.drawString("Level " + (level + 1), 280, Game.HEIGHT + 50);
       g2d.setColor(Color.BLUE);
       g2d.drawString(score + "", 670, Game.HEIGHT + 30);
       g2d.setColor(Color.RED);
       g2d.drawString(numDonuts + "/" + MAX_DONUTS, 450, Game.HEIGHT + 30);
     }
   } else {
     g2d.setColor(Color.CYAN);
     g2d.fillRect(0, 0, Game.WIDTH, Game.HEIGHT2);
     g2d.setFont(font.deriveFont(30f));
     g2d.setColor(Color.BLACK);
     if (perioTime % 12 > 0 && perioTime % 12 < 6) g2d.drawString("Please wait..", 320, 300);
     else g2d.drawString("Please wait...", 320, 300);
   }
 }
 /**
  * 再生状態を変更する
  *
  * @param nextState 次の状態
  */
 private void changeState(PlayState nextState) {
   mPlayState = nextState;
   mPlayState.init();
 }
 /**
  * 再生状態を取得する
  *
  * @return 再生状態
  * @see MediaPlayService#PLAY_STATE_IDLE
  * @see MediaPlayService#PLAY_STATE_PREPARE
  * @see MediaPlayService#PLAY_STATE_PLAYING
  */
 public int getPlayState() {
   return mPlayState.getPlayState();
 }
 public void setTimeline(GameStateTimeline gst) {
   timeline = new AudioTimeline(gst);
   timeline.setTargetState(playState);
   timeline.addObserver((o, arg) -> playState.play());
 }