Ejemplo n.º 1
0
 @SuppressLint("NewApi")
 @Override
 public void onDestroy() {
   super.onDestroy();
   if (remoteControlClient != null) {
     RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
     metadataEditor.clear();
     metadataEditor.apply();
     audioManager.unregisterRemoteControlClient(remoteControlClient);
   }
   NotificationCenter.getInstance()
       .removeObserver(this, NotificationCenter.audioProgressDidChanged);
   NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioPlayStateChanged);
 }
Ejemplo n.º 2
0
 protected void updateMetadata(
     final MusicDirectory.Entry currentSong, final RemoteControlClient.MetadataEditor editor) {
   editor
       .putString(
           MediaMetadataRetriever.METADATA_KEY_ARTIST,
           (currentSong == null) ? null : currentSong.getArtist())
       .putString(
           MediaMetadataRetriever.METADATA_KEY_ALBUM,
           (currentSong == null) ? null : currentSong.getAlbum())
       .putString(
           MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST,
           (currentSong == null) ? null : currentSong.getArtist())
       .putString(
           MediaMetadataRetriever.METADATA_KEY_TITLE,
           (currentSong) == null ? null : currentSong.getTitle())
       .putString(
           MediaMetadataRetriever.METADATA_KEY_GENRE,
           (currentSong) == null ? null : currentSong.getGenre())
       .putLong(
           MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER,
           (currentSong == null)
               ? 0
               : ((currentSong.getTrack() == null) ? 0 : currentSong.getTrack()))
       .putLong(
           MediaMetadataRetriever.METADATA_KEY_DURATION,
           (currentSong == null)
               ? 0
               : ((currentSong.getDuration() == null) ? 0 : (currentSong.getDuration() * 1000)));
 }
Ejemplo n.º 3
0
  public void updateMetadata(final Context context, final MusicDirectory.Entry currentSong) {
    if (mRemoteControl == null) {
      return;
    }

    if (imageLoader == null) {
      imageLoader = SubsonicActivity.getStaticImageLoader(context);
    }

    // Update the remote controls
    RemoteControlClient.MetadataEditor editor = mRemoteControl.editMetadata(true);
    updateMetadata(currentSong, editor);
    editor.apply();
    if (currentSong == null || imageLoader == null) {
      mRemoteControl
          .editMetadata(true)
          .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null)
          .apply();
    } else {
      imageLoader.loadImage(context, mRemoteControl, currentSong);
    }
  }
  /** Update the RemoteControlClient */
  private void updateRemoteControlClient() {
    // Update playstate
    if (App.mClementine.getState() == Clementine.State.PLAY) {
      mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    } else {
      mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
    }

    // Get the metadata editor
    if (mLastSong != null && mLastSong.getArt() != null) {
      RemoteControlClient.MetadataEditor editor = mRcClient.editMetadata(false);
      editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, mLastSong.getArt());

      // The RemoteControlClients displays the following info:
      // METADATA_KEY_TITLE (white) - METADATA_KEY_ALBUMARTIST (grey) - METADATA_KEY_ALBUM (grey)
      //
      // So i put the metadata not in the "correct" fields to display artist, track and album
      // TODO: Fix it when changed in newer android versions
      editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, mLastSong.getAlbum());
      editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, mLastSong.getArtist());
      editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, mLastSong.getTitle());
      editor.apply();
    }
  }
Ejemplo n.º 5
0
  @SuppressLint("NewApi")
  private void createNotification(MessageObject messageObject) {
    String songName = messageObject.getMusicTitle();
    String authorName = messageObject.getMusicAuthor();
    AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();

    RemoteViews simpleContentView =
        new RemoteViews(
            getApplicationContext().getPackageName(), R.layout.player_small_notification);
    RemoteViews expandedView = null;
    if (supportBigNotifications) {
      expandedView =
          new RemoteViews(
              getApplicationContext().getPackageName(), R.layout.player_big_notification);
    }

    Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
    intent.setAction("com.tmessages.openplayer");
    intent.setFlags(32768);
    PendingIntent contentIntent =
        PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0);

    Notification notification =
        new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.player)
            .setContentIntent(contentIntent)
            .setContentTitle(songName)
            .build();

    notification.contentView = simpleContentView;
    if (supportBigNotifications) {
      notification.bigContentView = expandedView;
    }

    setListeners(simpleContentView);
    if (supportBigNotifications) {
      setListeners(expandedView);
    }

    Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null;
    if (albumArt != null) {
      notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
      if (supportBigNotifications) {
        notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
      }
    } else {
      notification.contentView.setImageViewResource(
          R.id.player_album_art, R.drawable.nocover_small);
      if (supportBigNotifications) {
        notification.bigContentView.setImageViewResource(
            R.id.player_album_art, R.drawable.nocover_big);
      }
    }
    if (MediaController.getInstance().isDownloadingCurrentMessage()) {
      notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
      notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
      notification.contentView.setViewVisibility(R.id.player_next, View.GONE);
      notification.contentView.setViewVisibility(R.id.player_previous, View.GONE);
      notification.contentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
      if (supportBigNotifications) {
        notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
        notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
        notification.bigContentView.setViewVisibility(R.id.player_next, View.GONE);
        notification.bigContentView.setViewVisibility(R.id.player_previous, View.GONE);
        notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
      }
    } else {
      notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
      notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
      notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
      if (supportBigNotifications) {
        notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
      }

      if (MediaController.getInstance().isAudioPaused()) {
        notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
        if (supportBigNotifications) {
          notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
          notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
        }
      } else {
        notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
        if (supportBigNotifications) {
          notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
          notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
        }
      }
    }

    notification.contentView.setTextViewText(R.id.player_song_name, songName);
    notification.contentView.setTextViewText(R.id.player_author_name, authorName);
    if (supportBigNotifications) {
      notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
      notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
    }
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(5, notification);

    if (remoteControlClient != null) {
      RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
      metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
      metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
      if (audioInfo != null && audioInfo.getCover() != null) {
        try {
          metadataEditor.putBitmap(
              RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover());
        } catch (Throwable e) {
          FileLog.e("tmessages", e);
        }
      }
      metadataEditor.apply();
    }
  }