Example usage for android.support.v4.media MediaDescriptionCompat getTitle

List of usage examples for android.support.v4.media MediaDescriptionCompat getTitle

Introduction

In this page you can find the example usage for android.support.v4.media MediaDescriptionCompat getTitle.

Prototype

@Nullable
public CharSequence getTitle() 

Source Link

Document

Returns a title suitable for display or null.

Usage

From source file:org.tomahawk.tomahawk_android.utils.MediaNotification.java

private void updateNotificationMetadata() {

    try {/*from w w w  .  ja va2s .c om*/
        Log.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
        if (mMetadata == null || mPlaybackState == null) {
            return;
        }

        mNotificationBuilder = new NotificationCompat.Builder(mService);

        List<Integer> showInCompact = new ArrayList<>();

        // updateFavoriteAction();
        //            showInCompact.add(mNotificationBuilder.mActions.size());
        //            mNotificationBuilder.addAction(mFavoriteAction);

        // If skip to previous action is enabled
        if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
            NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                    R.drawable.ic_player_previous_light, mService.getString(R.string.playback_previous),
                    mIntents.get(R.drawable.ic_player_previous_light)).build();
            mNotificationBuilder.addAction(action);
        }

        updatePlayPauseAction();
        showInCompact.add(mNotificationBuilder.mActions.size());
        mNotificationBuilder.addAction(mPlayPauseAction);

        // If skip to next action is enabled
        if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
            NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                    R.drawable.ic_player_next_light, mService.getString(R.string.playback_next),
                    mIntents.get(R.drawable.ic_player_next_light)).build();
            showInCompact.add(mNotificationBuilder.mActions.size());
            mNotificationBuilder.addAction(action);
        }

        MediaDescriptionCompat description = mMetadata.getDescription();

        String playbackManagerId = mController.getExtras()
                .getString(PlaybackService.EXTRAS_KEY_PLAYBACKMANAGER);
        PlaybackManager playbackManager = PlaybackManager.getByKey(playbackManagerId);
        Image image = playbackManager.getCurrentQuery().getImage();
        Bitmap art = null;
        if (image != null) {
            art = MediaImageHelper.get().getMediaImageCache().get(image);
        }
        if (art == null) {
            art = MediaImageHelper.get().getCachedPlaceHolder();
        }

        mNotificationBuilder
                .setStyle(new NotificationCompat.MediaStyle()
                        .setShowActionsInCompactView(ArrayUtil.toIntArray(showInCompact))
                        .setMediaSession(mSessionToken).setShowCancelButton(true)
                        .setCancelButtonIntent(createCancelIntent()))
                .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setContentIntent(createContentIntent())
                .setContentTitle(description.getTitle()).setContentText(description.getSubtitle())
                .setTicker(description.getTitle() + " - " + description.getSubtitle()).setLargeIcon(art)
                .setOngoing(false);

        updateNotificationPlaybackState();

        mService.startForeground(NOTIFICATION_ID, mNotificationBuilder.build());
        Log.d(TAG, "updateNotificationMetadata. Notification shown");

    } catch (Exception e) {

    }
}

From source file:com.example.android.mediabrowserservice.MediaNotificationManager.java

private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }/*  ww  w .j av  a 2 s. c  om*/

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp,
                mService.getString(R.string.label_previous), mPreviousIntent);

        // If there is a "skip to previous" button, the play/pause button will
        // be the second one. We need to keep track of it, because the MediaStyle notification
        // requires to specify the index of the buttons (actions) that should be visible
        // when in compact view.
        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    // If skip to next action is enabled
    if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp,
                mService.getString(R.string.label_next), mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;
    if (description.getIconUri() != null) {
        // This sample assumes the iconUri will be a valid URL formatted String, but
        // it can actually be any valid Android Uri formatted String.
        // async fetch the album art icon
        String artUrl = description.getIconUri().toString();
        art = AlbumArtCache.getInstance().getBigImage(artUrl);
        if (art == null) {
            fetchArtUrl = artUrl;
            // use a placeholder art while the remote art is being downloaded
            art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art);
        }
    }

    notificationBuilder
            .setStyle(new NotificationCompat.MediaStyle()
                    .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view
                    .setMediaSession(mSessionToken))
            .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification)
            .setVisibility(Notification.VISIBILITY_PUBLIC).setUsesChronometer(true)
            .setContentIntent(createContentIntent()).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    setNotificationPlaybackState(notificationBuilder);
    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}

From source file:com.bayapps.android.robophish.MediaNotificationManager.java

private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }//from w w  w .  j ava 2 s.  c  o  m

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp,
                mService.getString(R.string.label_previous), mPreviousIntent);

        // If there is a "skip to previous" button, the play/pause button will
        // be the second one. We need to keep track of it, because the MediaStyle notification
        // requires to specify the index of the buttons (actions) that should be visible
        // when in compact view.
        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    // If skip to next action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp,
                mService.getString(R.string.label_next), mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;
    if (description.getIconUri() != null) {
        // This sample assumes the iconUri will be a valid URL formatted String, but
        // it can actually be any valid Android Uri formatted String.
        // async fetch the album art icon
        String artUrl = description.getIconUri().toString();
        art = AlbumArtCache.getInstance().getBigImage(artUrl);
        if (art == null) {
            fetchArtUrl = artUrl;
            // use a placeholder art while the remote art is being downloaded
            art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art);
        }
    }

    notificationBuilder
            .setStyle(new NotificationCompat.MediaStyle()
                    .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view
                    .setMediaSession(mSessionToken))
            .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setUsesChronometer(true)
            .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    if (mController != null && mController.getExtras() != null) {
        String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            String castInfo = mService.getResources().getString(R.string.casting_to_device, castName);
            notificationBuilder.setSubText(castInfo);
            notificationBuilder.addAction(R.drawable.ic_close_black_24dp,
                    mService.getString(R.string.stop_casting), mStopCastIntent);
        }
    }

    setNotificationPlaybackState(notificationBuilder);
    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}

From source file:org.copticchurchlibrary.arabicreader.MediaNotificationManager.java

private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }//from   ww w.ja v a2  s . c  o  m

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(
                org.copticchurchlibrary.arabicreader.R.drawable.ic_skip_previous_white_24dp,
                mService.getString(org.copticchurchlibrary.arabicreader.R.string.label_previous),
                mPreviousIntent);

        // If there is a "skip to previous" button, the play/pause button will
        // be the second one. We need to keep track of it, because the MediaStyle notification
        // requires to specify the index of the buttons (actions) that should be visible
        // when in compact view.
        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    // If skip to next action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(org.copticchurchlibrary.arabicreader.R.drawable.ic_skip_next_white_24dp,
                mService.getString(org.copticchurchlibrary.arabicreader.R.string.label_next), mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;
    if (description.getIconUri() != null) {
        // This sample assumes the iconUri will be a valid URL formatted String, but
        // it can actually be any valid Android Uri formatted String.
        // async fetch the album art icon
        String artUrl = description.getIconUri().toString();
        art = AlbumArtCache.getInstance().getBigImage(artUrl);
        if (art == null) {
            fetchArtUrl = artUrl;
            // use a placeholder art while the remote art is being downloaded
            art = BitmapFactory.decodeResource(mService.getResources(),
                    org.copticchurchlibrary.arabicreader.R.drawable.ic_default_art);
        }
    }

    notificationBuilder
            .setStyle(new NotificationCompat.MediaStyle()
                    .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view
                    .setMediaSession(mSessionToken))
            .setColor(mNotificationColor)
            .setSmallIcon(org.copticchurchlibrary.arabicreader.R.drawable.ic_notification)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setUsesChronometer(true)
            .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    if (mController != null && mController.getExtras() != null) {
        String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            String castInfo = mService.getResources()
                    .getString(org.copticchurchlibrary.arabicreader.R.string.casting_to_device, castName);
            notificationBuilder.setSubText(castInfo);
            notificationBuilder.addAction(org.copticchurchlibrary.arabicreader.R.drawable.ic_close_black_24dp,
                    mService.getString(org.copticchurchlibrary.arabicreader.R.string.stop_casting),
                    mStopCastIntent);
        }
    }

    setNotificationPlaybackState(notificationBuilder);
    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}

From source file:com.torrenttunes.android.MediaNotificationManager.java

private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }/*w w w .  j  a  va  2 s  . co  m*/

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp,
                mService.getString(R.string.label_previous), mPreviousIntent);

        // If there is a "skip to previous" button, the play/pause button will
        // be the second one. We need to keep track of it, because the MediaStyle notification
        // requires to specify the index of the buttons (actions) that should be visible
        // when in compact view.
        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    // If skip to next action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp,
                mService.getString(R.string.label_next), mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;
    if (description.getIconUri() != null) {
        // This sample assumes the iconUri will be a valid URL formatted String, but
        // it can actually be any valid Android Uri formatted String.
        // async fetch the album art icon
        String artUrl = description.getIconUri().toString();
        art = AlbumArtCache.getInstance().getBigImage(artUrl);
        if (art == null) {
            fetchArtUrl = artUrl;
            // use a placeholder art while the remote art is being downloaded
            art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art);
        }
        if (art.isRecycled()) {
            art = null;
        }
    }

    notificationBuilder
            //                .setStyle(new Notification.MediaStyle()
            //                        .setShowActionsInCompactView(
            //                                new int[]{playPauseButtonPosition})  // show only play/pause in compact view
            //                        .setMediaSession(mSessionToken))
            .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification)
            .setVisibility(Notification.VISIBILITY_PUBLIC).setUsesChronometer(true)
            .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    if (mController != null && mController.getExtras() != null) {
        String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            String castInfo = mService.getResources().getString(R.string.casting_to_device, castName);
            notificationBuilder.setSubText(castInfo);
            notificationBuilder.addAction(R.drawable.ic_close_black_24dp,
                    mService.getString(R.string.stop_casting), mStopCastIntent);
        }
    }

    setNotificationPlaybackState(notificationBuilder);
    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}

From source file:com.murati.oszk.audiobook.MediaNotificationManager.java

private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }//  www  .ja v  a 2s.c o  m

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp,
                mService.getString(R.string.label_previous), mPreviousIntent);

        // If there is a "skip to previous" button, the play/pause button will
        // be the second one. We need to keep track of it, because the MediaStyle notification
        // requires to specify the index of the buttons (actions) that should be visible
        // when in compact view.
        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    // If skip to next action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp,
                mService.getString(R.string.label_next), mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;
    if (description.getIconUri() != null) {
        // This sample assumes the iconUri will be a valid URL formatted String, but
        // it can actually be any valid Android Uri formatted String.
        // async fetch the album art icon
        String artUrl = description.getIconUri().toString();

        try {
            //art = GlideApp.with(mService.getBaseContext()).asBitmap().load(artUrl).submit().get();

            art = AlbumArtCache.getInstance().getBigImage(artUrl);

        } catch (Exception ex) {
            Log.d(TAG, ex.getMessage());
        }
        if (art == null) {
            fetchArtUrl = artUrl;
            // use a placeholder art while the remote art is being downloaded
            art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_launcher_white);
        }
    }

    notificationBuilder
            .setStyle(new NotificationCompat.MediaStyle()
                    .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view
                    .setMediaSession(mSessionToken))
            .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_launcher_white)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setUsesChronometer(true)
            .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    if (mController != null && mController.getExtras() != null) {
        String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            String castInfo = mService.getResources().getString(R.string.casting_to_device, castName);
            notificationBuilder.setSubText(castInfo);
            notificationBuilder.addAction(R.drawable.ic_close_black_24dp,
                    mService.getString(R.string.stop_casting), mStopCastIntent);
        }
    }

    setNotificationPlaybackState(notificationBuilder);
    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}

From source file:com.allthatseries.RNAudioPlayer.MediaNotificationManager.java

private Notification createNotification() {
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }/* www .  j  a va2s  . com*/

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, "previous", mPreviousIntent);

        // If there is a "skip to previous" button, the play/pause button will
        // be the second one. We need to keep track of it, because the MediaStyle notification
        // requires to specify the index of the buttons (actions) that should be visible
        // when in compact view.
        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    // If skip to next action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, "next", mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;
    if (description.getIconUri() != null) {
        // This sample assumes the iconUri will be a valid URL formatted String, but
        // it can actually be any valid Android Uri formatted String.
        // async fetch the album art icon
        String artUrl = description.getIconUri().toString();
        art = AlbumArtCache.getInstance().getBigImage(artUrl);
        if (art == null) {
            fetchArtUrl = artUrl;
            // use a placeholder art while the remote art is being downloaded
            art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art);
        }
    }

    // Basically we use notification icon but it doesn't exist we use launcher icon
    Context context = mService.getApplicationContext();
    int resId = context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName());
    if (resId == 0) {
        resId = context.getResources().getIdentifier("ic_launcher", "mipmap", context.getPackageName());
    }

    notificationBuilder
            .setStyle(new NotificationCompat.MediaStyle()
                    .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view
                    .setMediaSession(mSessionToken))
            .setColor(0xffdf533b).setSmallIcon(resId).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setUsesChronometer(true).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    setNotificationPlaybackState(notificationBuilder);

    // We should get MainActivity.class to set pendingIntent
    // If there exists better way, it should place this logic
    String packageName = mService.getApplicationContext().getPackageName();
    Intent launchIntent = mService.getApplicationContext().getPackageManager()
            .getLaunchIntentForPackage(packageName);
    String className = launchIntent.getComponent().getClassName();

    try {
        Class activityClass = Class.forName(className);
        notificationBuilder.setContentIntent(createContentIntent(activityClass));
    } catch (Exception e) {
        // do nothing
    }

    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}