示例#1
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();
  }
示例#2
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;
    }
  }
示例#3
0
  private MediaPlayer getMediaPlayer() {
    if (mMediaPlayer == null) {

      final app2 mapp = (app2) context.getApplicationContext();
      mMediaPlayer = mapp.getMusicaService().getmMediaPlayer();
    }
    return mMediaPlayer;
  }
示例#4
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()));
    }
  }
示例#5
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();
                }
              }
            });
  }