當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaMetadataCompat.getDescription方法代碼示例

本文整理匯總了Java中android.support.v4.media.MediaMetadataCompat.getDescription方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaMetadataCompat.getDescription方法的具體用法?Java MediaMetadataCompat.getDescription怎麽用?Java MediaMetadataCompat.getDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.media.MediaMetadataCompat的用法示例。


在下文中一共展示了MediaMetadataCompat.getDescription方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: from

import android.support.v4.media.MediaMetadataCompat; //導入方法依賴的package包/類
/**
 * Build a notification using the information from the given media session. Makes heavy use
 * of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
 *
 * @param context      Context used to construct the notification.
 * @param mediaSession Media session to get information.
 * @return A pre-built notification with information from the given media session.
 */
static NotificationCompat.Builder from(
        Context context, MediaSessionCompat mediaSession) {
    MediaControllerCompat controller = mediaSession.getController();
    MediaMetadataCompat mediaMetadata = controller.getMetadata();
    MediaDescriptionCompat description = mediaMetadata.getDescription();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setSubText(description.getDescription())
            .setLargeIcon(description.getIconBitmap())
            .setContentIntent(controller.getSessionActivity())
            .setDeleteIntent(
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    return builder;
}
 
開發者ID:SergeyVinyar,項目名稱:AndroidAudioExample,代碼行數:27,代碼來源:MediaStyleHelper.java

示例2: createStopNotification

import android.support.v4.media.MediaMetadataCompat; //導入方法依賴的package包/類
public static void createStopNotification(MediaSessionCompat mediaSession, Service context, Class<?> serviceClass, int NOTIFICATION_ID) {

        PendingIntent stopIntent = PendingIntent
                .getService(context, 0, getIntent(MediaRecorderService.REQUEST_TYPE_STOP, context, serviceClass),
                        PendingIntent.FLAG_CANCEL_CURRENT);

        MediaControllerCompat controller = mediaSession.getController();
        MediaMetadataCompat mediaMetadata = controller.getMetadata();
        MediaDescriptionCompat description = mediaMetadata.getDescription();
        // Start foreground service to avoid unexpected kill
        Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle(description.getTitle())
                .setContentText(description.getSubtitle())
                .setSubText(description.getDescription())
                .setLargeIcon(description.getIconBitmap())
                .setDeleteIntent(stopIntent)
                // Add a pause button
                .addAction(new android.support.v7.app.NotificationCompat.Action(
                        R.drawable.ic_stop_black_24dp, context.getString(R.string.stop),
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_STOP)))
                .setStyle(new android.support.v7.app.NotificationCompat.MediaStyle()
                        .setMediaSession(mediaSession.getSessionToken())
                        .setShowActionsInCompactView(0)
                        .setShowCancelButton(true)
                        .setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_STOP)))
                .setSmallIcon(R.drawable.ic_album_black_24dp)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .build();

        context.startForeground(NOTIFICATION_ID, notification);
    }
 
開發者ID:aschober,項目名稱:vinyl-cast,代碼行數:34,代碼來源:Helpers.java

示例3: getNotification

import android.support.v4.media.MediaMetadataCompat; //導入方法依賴的package包/類
public Notification getNotification(MediaMetadataCompat metadata,
                                    @NonNull PlaybackStateCompat state,
                                    MediaSessionCompat.Token token) {
    boolean isPlaying = state.getState() == PlaybackStateCompat.STATE_PLAYING;
    MediaDescriptionCompat description = metadata.getDescription();
    NotificationCompat.Builder builder =
            buildNotification(state, token, isPlaying, description);
    return builder.build();
}
 
開發者ID:nazmulidris,項目名稱:mediasession-mediaplayer,代碼行數:10,代碼來源:MediaNotificationManager.java

示例4: update

import android.support.v4.media.MediaMetadataCompat; //導入方法依賴的package包/類
public void update(
        MediaMetadataCompat metadata,
        PlaybackStateCompat state,
        MediaSessionCompat.Token token) {
    if (state == null
            || state.getState() == PlaybackStateCompat.STATE_STOPPED
            || state.getState() == PlaybackStateCompat.STATE_NONE) {
        mService.stopForeground(true);
        try {
            mService.unregisterReceiver(this);
        } catch (IllegalArgumentException ex) {
            // ignore receiver not registered
        }
        mService.stopSelf();
        return;
    }
    if (metadata == null) {
        return;
    }
    boolean isPlaying = state.getState() == PlaybackStateCompat.STATE_PLAYING;
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    MediaDescriptionCompat description = metadata.getDescription();

    notificationBuilder
            .setStyle(
                    new NotificationCompat.MediaStyle()
                            .setMediaSession(token)
                            .setShowActionsInCompactView(0, 1, 2))
            .setColor(
                    mService.getApplication().getResources().getColor(R.color.notification_bg))
            .setSmallIcon(R.drawable.ic_notification)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setContentIntent(createContentIntent())
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setLargeIcon(MusicLibrary.getAlbumBitmap(mService, description.getMediaId()))
            .setOngoing(isPlaying)
            .setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0)
            .setShowWhen(isPlaying)
            .setUsesChronometer(isPlaying);

    // If skip to next action is enabled
    if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(mPrevAction);
    }

    notificationBuilder.addAction(isPlaying ? mPauseAction : mPlayAction);

    // If skip to prev action is enabled
    if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(mNextAction);
    }

    Notification notification = notificationBuilder.build();

    if (isPlaying && !mStarted) {
        mService.startService(new Intent(mService.getApplicationContext(), MusicService.class));
        mService.startForeground(NOTIFICATION_ID, notification);
        mStarted = true;
    } else {
        if (!isPlaying) {
            mService.stopForeground(false);
            mStarted = false;
        }
        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:68,代碼來源:MediaNotificationManager.java

示例5: createMediaItem

import android.support.v4.media.MediaMetadataCompat; //導入方法依賴的package包/類
private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
    return new MediaBrowserCompat.MediaItem(metadata.getDescription(),
            MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
}
 
開發者ID:Jaysaw,項目名稱:NovaMusicPlayer,代碼行數:5,代碼來源:MusicProvider.java

示例6: buildNotification

import android.support.v4.media.MediaMetadataCompat; //導入方法依賴的package包/類
public static Notification buildNotification(Context context, MediaSessionCompat session) {

        MediaControllerCompat controller = session.getController();
        MediaMetadataCompat metadata = controller.getMetadata();
        PlaybackStateCompat playbackState = controller.getPlaybackState();

        if ((metadata == null) || (playbackState == null)) {
            return null;
        }

        boolean isPlaying = playbackState.getState() == PlaybackStateCompat.STATE_PLAYING;
        NotificationCompat.Action action = isPlaying ?
                new NotificationCompat.Action(android.R.drawable.ic_media_pause,
                        context.getString(R.string.pause),
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_PAUSE)) :
                new NotificationCompat.Action(android.R.drawable.ic_media_play,
                        context.getString(R.string.play),
                        MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                                PlaybackStateCompat.ACTION_PLAY));

        MediaDescriptionCompat description = metadata.getDescription();
        Bitmap albumArt = description.getIconBitmap();
        if (albumArt == null) {
            albumArt = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
        }


        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MusicService.NOTIFICATION_CHANNEL_ID);
        builder.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
//                .setShowActionsInCompactView(new int[]{0})
.setMediaSession(session.getSessionToken()))
                .addAction(action)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setShowWhen(false)
                .setContentIntent(controller.getSessionActivity())
                .setContentTitle(description.getTitle())
                .setContentText(description.getSubtitle())
                .setLargeIcon(albumArt)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

        return builder.build();
    }
 
開發者ID:Jaysaw,項目名稱:NovaMusicPlayer,代碼行數:44,代碼來源:NotificationHelper.java


注:本文中的android.support.v4.media.MediaMetadataCompat.getDescription方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。