Exemplo n.º 1
0
  @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);
  }
Exemplo n.º 2
0
  public void play() {

    // if play button itself is null, the whole purpose of AudioWife is
    // defeated.
    if (mPlayButton == null) {
      throw new IllegalStateException(ERROR_PLAYVIEW_NULL);
    }

    if (mUri == null) {
      throw new IllegalStateException("Uri cannot be null. Call init() before calling this method");
    }

    if (mMediaPlayer == null) {
      throw new IllegalStateException("Call init() before calling this method");
    }

    if (getMediaPlayer().isPlaying()) {
      return;
    }

    mProgressUpdateHandler.postDelayed(mUpdateProgress, AUDIO_PROGRESS_UPDATE_TIME);

    // enable visibility of all UI controls.
    setViewsVisibility();
    app2 mapp = (app2) context.getApplicationContext();
    mapp.getBaseactivity()
        .ShowMiniPlayer(
            mapp.getMusicaService()
                .getSongtoplay()
                .get(mapp.getMusicaService().getSelectedtrackindex()));
    mapp.getMusicaService().start();
    setPausable();
  }
Exemplo n.º 3
0
  private MediaPlayer getMediaPlayer() {
    if (mMediaPlayer == null) {

      final app2 mapp = (app2) context.getApplicationContext();
      mMediaPlayer = mapp.getMusicaService().getmMediaPlayer();
    }
    return mMediaPlayer;
  }
Exemplo n.º 4
0
  public void release() {

    if (mMediaPlayer != null) {
      mMediaPlayer.stop();
      mMediaPlayer.reset();
      mMediaPlayer.release();
      mMediaPlayer = null;
      app2 mapp = (app2) context.getApplicationContext();
      mapp.getMusicaService().InitMediaPlayer();
      mMediaPlayer = mapp.getMusicaService().getmMediaPlayer();

      mProgressUpdateHandler = null;
    }
  }
Exemplo n.º 5
0
  public void pause() {

    if (getMediaPlayer() == null) {
      return;
    }

    if (getMediaPlayer().isPlaying()) {
      app2 mapp = (app2) context.getApplicationContext();
      mapp.getMusicaService().stop();
      setPlayable();

      mapp.getBaseactivity()
          .ShowMiniPlayer(
              mapp.getMusicaService()
                  .getSongtoplay()
                  .get(mapp.getMusicaService().getSelectedtrackindex()));
    }
  }
Exemplo n.º 6
0
  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);
  }
Exemplo n.º 7
0
  /** ** Initialize and prepare the audio player ** */
  private void initPlayer(final Context ctx) {

    this.context = ctx;
    if (loadingView != null) {
      loadingView.setVisibility(View.VISIBLE);
    }
    final app2 mapp = (app2) ctx.getApplicationContext();

    final song d =
        mapp.getMusicaService()
            .getSongtoplay()
            .get(mapp.getMusicaService().getSelectedtrackindex());
    getMediaPlayer()
        .setOnCompletionListener(
            new OnCompletionListener() {

              @Override
              public void onCompletion(MediaPlayer arg0) {
                // TODO Auto-generated method stub
                // set UI when audio finished playing
                int currentPlayTime = 0;
                updateRuntime(currentPlayTime);
                // setPlayable();
                if (arg0.getCurrentPosition() > 13) {
                  if (mapp.getMusicaService().getSelectedtrackindex()
                      != mapp.getMusicaService().getSongtoplay().size() - 1) {
                    mapp.getMusicaService()
                        .setSelectedtrackindex(mapp.getMusicaService().getSelectedtrackindex() + 1);

                    mapp.getBaseactivity()
                        .updateList_Playsong(
                            mapp.getMusicaService()
                                .getSongtoplay()
                                .get(mapp.getMusicaService().getSelectedtrackindex()));

                    if (mapp.isFullPlayerisshown == true) mapp.PlayerActivity.recreate();
                  }
                  mapp.getBaseactivity()
                      .ShowMiniPlayer(
                          mapp.getMusicaService()
                              .getSongtoplay()
                              .get(mapp.getMusicaService().getSelectedtrackindex()));
                }
                try {
                  mapp.PlayerActivity.initializeViewsandPlay(
                      mapp.getMusicaService()
                          .getSongtoplay()
                          .get(mapp.getMusicaService().getSelectedtrackindex()));
                  mSeekBar.setProgress((int) currentPlayTime);

                } catch (Exception d) {
                  app2 mapp = (app2) context.getApplicationContext();
                  mapp.getInstance().trackException(d);
                }
              }
            });
    getMediaPlayer()
        .setOnPreparedListener(
            new OnPreparedListener() {

              @Override
              public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub

                getMediaPlayer().start();
                mapp.getBaseactivity().ShowMiniPlayer(d);
                updateUI();
                initMediaSeekBar();
                updatePlaytime(0);
                if (loadingView != null) {
                  loadingView.setVisibility(View.GONE);
                }
              }
            });

    new Handler()
        .post(
            new Runnable() {
              @Override
              public void run() {
                // Code here will run in UI thread
                try {
                  StrictMode.ThreadPolicy policy =
                      new StrictMode.ThreadPolicy.Builder().permitAll().build();
                  StrictMode.setThreadPolicy(policy);
                  String urp = tools.getLocation(mUri.toString());
                  getMediaPlayer().setDataSource(urp);
                  getMediaPlayer().prepareAsync();
                } catch (Exception e) {

                  mapp.getInstance().trackException(e);
                  Toast.makeText(
                          context,
                          context.getResources().getString(R.string.error),
                          Toast.LENGTH_LONG)
                      .show();
                }
              }
            });
  }