From 4fc36f242282d5af5e3a4254729b1a93dc44b98a Mon Sep 17 00:00:00 2001 From: "Warren R. Bank" Date: Mon, 30 Mar 2020 14:12:20 -0700 Subject: [PATCH] improve title displayed in notification for active media item add position of item in media queue: [p/t] => position of total --- .../PlayerNotificationManagerContainer.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/exoplayer2/PlayerNotificationManagerContainer.java b/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/exoplayer2/PlayerNotificationManagerContainer.java index 3ec9560..112ed21 100644 --- a/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/exoplayer2/PlayerNotificationManagerContainer.java +++ b/android-studio-project/ExoPlayer-AirPlay-Receiver/src/main/java/com/github/warren_bank/exoplayer_airplay_receiver/exoplayer2/PlayerNotificationManagerContainer.java @@ -141,22 +141,32 @@ private URI getMediaItemUri(int currentItemIndex) { // =========================================================================== private String getMediaItemTitle(int currentItemIndex) { - return getMediaItemTitle(getMediaItemUri(currentItemIndex)); + return getMediaItemTitle(currentItemIndex, getMediaItemUri(currentItemIndex)); } - private String getMediaItemTitle(URI uri) { + private String getMediaItemTitle(int currentItemIndex, URI uri) { if (uri == null) return null; boolean isAudio = VideoSource.isAudioFileUrl(uri.toString()); - return getMediaItemTitle(uri, isAudio); + return getMediaItemTitle(currentItemIndex, uri, isAudio); } - private String getMediaItemTitle(URI uri, boolean isAudio) { + private String getMediaItemTitle(int currentItemIndex, URI uri, boolean isAudio) { if (uri == null) return null; - return isAudio + int position_current, position_last; + String queuePosition, mimeType, title; + + position_current = currentItemIndex + 1; + position_last = playerManager.getMediaQueueSize(); + queuePosition = String.format("[%d/%d]", position_current, position_last); + + mimeType = isAudio ? "audio/" + VideoSource.get_audio_fileExtension(uri.toString()) : VideoSource.get_video_mimeType(uri.toString()); + + title = queuePosition + " " + mimeType; + return title; } // =========================================================================== @@ -266,10 +276,10 @@ private MediaDescriptionCompat getMediaDesc(int currentItemIndex) { boolean isAudio = VideoSource.isAudioFileUrl(uri.toString()); - String mediaId = uri.toString(); // URL - String title = getMediaItemTitle(uri, isAudio); // mime-type - String description = getMediaItemDescription(uri, isAudio); // hostname (stream) or dirname/filename (non-stream) - Bitmap bitmap = getMediaItemBitmap(uri, isAudio); // material icon to indicate audio or video + String mediaId = uri.toString(); // URL + String title = getMediaItemTitle(currentItemIndex, uri, isAudio); // [index/total] mime-type + String description = getMediaItemDescription(uri, isAudio); // hostname (stream) or dirname/filename (non-stream) + Bitmap bitmap = getMediaItemBitmap(uri, isAudio); // material icon to indicate audio or video Bundle extras = new Bundle(); extras.putParcelable(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap);