コード例 #1
0
 private void initiatePlayButtonState() {
   if (mMediaService.isPlaying()) {
     mPlayButton.setImageResource(R.drawable.ic_pause_black_36dp);
   } else if (mIsCompletedPlaying) {
     mPlayButton.setImageResource(R.drawable.ic_replay_black_36dp);
   } else if (mMediaService.isPaused()) {
     mPlayButton.setImageResource(R.drawable.ic_play_black_36dp);
   }
 }
コード例 #2
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    LayoutInflater inflater = getActivity().getLayoutInflater();
    mRootView = inflater.inflate(R.layout.fragment_dialog_player, null);
    builder.setView(mRootView);

    initializeViews();

    if (savedInstanceState != null) {
      mDoPlayTrack = savedInstanceState.getBoolean("doPlayTrack");
      mPosition = savedInstanceState.getInt("position");
      mPreviewUrl = savedInstanceState.getString("previewUrl");
      mTrackInfos = savedInstanceState.getParcelableArrayList("tracklist");
      mArtist = savedInstanceState.getString("artist");
      int mScrubBarPosition = savedInstanceState.getInt("seekPosition");
      mMediaService = MediaService.getMediaServiceInstance();
      if (!mMediaService.isPlaying()) {
        mScrubBar.setEnabled(false);
        mScrubBar.setProgress(mScrubBarPosition);
      } else {
        mScrubBar.setEnabled(true);
      }

      setAlbumArt(mArtist, mTrackInfos.get(mPosition));

      mFormatedDuration = savedInstanceState.getString("trackDuration");
      mDurationTextView.setText("(" + mFormatedDuration + ")");

      mFormatterPlayed = savedInstanceState.getString("trackPlayed");
      mTimePlayedView.setText(mFormatterPlayed);

      initiatePlayButtonState();
      initializeOnClicks();
    }

    if (MediaService.getMediaServiceInstance() != null) {
      initializeMediaService();
    }
    AlertDialog alertDialog = builder.create();
    alertDialog.setCanceledOnTouchOutside(false);

    return alertDialog;
  }
コード例 #3
0
  public void initializeMediaService() {
    mMediaService = MediaService.getMediaServiceInstance();
    if (mDoPlayTrack) {
      //            mMusicLoadingDialog = ProgressDialog.show(getActivity(), "Buffering", "Buffering
      // track. " +
      //                    "\n Please wait...", false, false);

      mMediaService.playPreview(mArtist, mPosition, mTrackInfos);
    }

    initiatePlayButtonState();
    initializeOnClicks();

    TrackInfo track = mTrackInfos.get(mPosition);
    setTrackDuration(track.getDuration());
    setAlbumArt(mArtist, track);

    mDoPlayTrack = true;
  }
コード例 #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setCancelable(true);

    if (MediaService.getMediaServiceInstance() == null) {
      Intent serviceForegroundIntent = new Intent();
      serviceForegroundIntent.setClass(getActivity(), MediaService.class);
      getActivity().startService(serviceForegroundIntent);
    }
  }