Esempio n. 1
0
  private void refreshPodcast() {
    if (_player == null) return;

    PlayerStatus status = PlayerStatus.getCurrentState(this);
    if (!status.hasActivePodcast()) {
      _player.stop();
      return;
    }

    if (status.getPodcastId() != _currentPodcastId) {
      _currentPodcastId = status.getPodcastId();
      if (!_player.prepare(status.getFilename(), status.getPosition())) {
        _player.stop();
        String toastMessage =
            getResources().getString(R.string.cannot_play_podcast, status.getTitle());
        Toast.makeText(this, toastMessage, Toast.LENGTH_LONG).show();
      } else {
        QueueManager.changeActivePodcast(this, status.getPodcastId());
        _lockscreenManager.setupLockscreenControls(this, status);
        showNotification();
      }
    } else {
      _player.seekTo(status.getPosition());
    }
  }
Esempio n. 2
0
 private void prepareNextPodcast() {
   PlayerStatus currentState = PlayerStatus.getCurrentState(this);
   if (!currentState.hasActivePodcast()) {
     _player.stop();
   } else {
     _player.prepare(currentState.getFilename(), currentState.getPosition());
     _currentPodcastId = currentState.getPodcastId();
   }
 }
Esempio n. 3
0
  private void showNotification() {
    String[] projection =
        new String[] {
          PodcastProvider.COLUMN_ID,
          PodcastProvider.COLUMN_TITLE,
          PodcastProvider.COLUMN_SUBSCRIPTION_ID,
          PodcastProvider.COLUMN_SUBSCRIPTION_TITLE,
          PodcastProvider.COLUMN_SUBSCRIPTION_THUMBNAIL,
        };
    Cursor c =
        getContentResolver()
            .query(PodcastProvider.ACTIVE_PODCAST_URI, projection, null, null, null);
    if (c == null) return;
    if (c.isAfterLast()) {
      c.close();
      return;
    }
    PodcastCursor podcast = new PodcastCursor(c);

    // both paths use the pendingintent
    Intent showIntent = new Intent(this, MainActivity.class);
    PendingIntent showPendingIntent = PendingIntent.getActivity(this, 0, showIntent, 0);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setWhen(0)
            .setContentTitle(podcast.getTitle())
            .setContentText(podcast.getSubscriptionTitle())
            .setContentIntent(showPendingIntent)
            .setOngoing(true)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);

    // set up pause intent
    Intent pauseIntent = new Intent(this, PlayerService.class);
    // use data to make intent unique
    pauseIntent.setData(Uri.parse("podax://playercommand/playpause"));
    pauseIntent.putExtra(Constants.EXTRA_PLAYER_COMMAND, Constants.PLAYER_COMMAND_PLAYPAUSE);
    pauseIntent.putExtra(Constants.EXTRA_PLAYER_COMMAND_ARG, Constants.PAUSE_MEDIABUTTON);
    PendingIntent pausePendingIntent = PendingIntent.getService(this, 0, pauseIntent, 0);

    // set up forward intent
    Intent forwardIntent = new Intent(this, ActivePodcastReceiver.class);
    forwardIntent.setData(Constants.ACTIVE_PODCAST_DATA_FORWARD);
    PendingIntent forwardPendingIntent = PendingIntent.getService(this, 0, forwardIntent, 0);

    Bitmap subscriptionBitmap =
        Helper.getCachedImage(this, podcast.getSubscriptionThumbnailUrl(), 128, 128);
    if (subscriptionBitmap != null) builder.setLargeIcon(subscriptionBitmap);

    if (PlayerStatus.getPlayerState(this) == PlayerStates.PLAYING)
      builder.addAction(
          R.drawable.ic_media_pause_normal, getString(R.string.pause), pausePendingIntent);
    else
      builder.addAction(
          R.drawable.ic_media_play_normal, getString(R.string.play), pausePendingIntent);
    builder.addAction(
        R.drawable.ic_media_ff_normal, getString(R.string.fast_forward), forwardPendingIntent);

    Notification notification = builder.build();
    startForeground(Constants.NOTIFICATION_PLAYING, notification);

    c.close();
  }