コード例 #1
0
ファイル: AudioWife.java プロジェクト: ayia/thedge
  @Deprecated
  private void updatePlaytime(int currentTime) {
    StringBuilder playbackStr = new StringBuilder();

    long totalDuration = 0;

    if (getMediaPlayer() != null) {
      try {
        totalDuration = getMediaPlayer().getDuration();
      } catch (Exception e) {
        app2 mapp = (app2) context.getApplicationContext();
        mapp.getInstance().trackException(e);
        e.printStackTrace();
      }
    }

    // set total time as the audio is being played
    if (totalDuration != 0) {
      playbackStr.append(
          String.format(
              "%02d:%02d",
              TimeUnit.MILLISECONDS.toMinutes((long) totalDuration),
              TimeUnit.MILLISECONDS.toSeconds((long) totalDuration)
                  - TimeUnit.MINUTES.toSeconds(
                      TimeUnit.MILLISECONDS.toMinutes((long) totalDuration))));
    } else {
      Log.w(TAG, "Something strage this audio track duration in zero");
    }

    mTotalTime.setText(playbackStr);

    // DebugLog.i(currentTime + " / " + totalDuration);
  }
コード例 #2
0
ファイル: AudioWife.java プロジェクト: ayia/thedge
  private void setTotalTime() {

    if (mTotalTime == null) {
      // this view can be null if the user
      // does not want to use it. Don't throw
      // an exception.
      return;
    }

    StringBuilder playbackStr = new StringBuilder();
    long totalDuration = 0;

    // by this point the media player is brought to ready state
    // by the call to init().
    if (getMediaPlayer() != null) {
      try {
        totalDuration = getMediaPlayer().getDuration();

      } catch (Exception e) {
        app2 mapp = (app2) context.getApplicationContext();
        mapp.getInstance().trackException(e);
        e.printStackTrace();
      }
    }

    if (totalDuration < 0) {
      throw new IllegalArgumentException(ERROR_PLAYTIME_TOTAL_NEGATIVE);
    }

    // set total time as the audio is being played
    if (totalDuration != 0) {
      playbackStr.append(
          String.format(
              "%02d:%02d",
              TimeUnit.MILLISECONDS.toMinutes((long) totalDuration),
              TimeUnit.MILLISECONDS.toSeconds((long) totalDuration)
                  - TimeUnit.MINUTES.toSeconds(
                      TimeUnit.MILLISECONDS.toMinutes((long) totalDuration))));
    }

    mTotalTime.setText(playbackStr);
  }