当前位置: 首页>>代码示例>>Java>>正文


Java MediaDescription.getIconUri方法代码示例

本文整理汇总了Java中android.media.MediaDescription.getIconUri方法的典型用法代码示例。如果您正苦于以下问题:Java MediaDescription.getIconUri方法的具体用法?Java MediaDescription.getIconUri怎么用?Java MediaDescription.getIconUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaDescription的用法示例。


在下文中一共展示了MediaDescription.getIconUri方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createNotification

import android.media.MediaDescription; //导入方法依赖的package包/类
private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }

    Notification.Builder notificationBuilder = new Notification.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);
    }

    MediaDescription 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 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();
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:80,代码来源:MediaNotificationManager.java

示例2: createNotification

import android.media.MediaDescription; //导入方法依赖的package包/类
private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }

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

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(com.chinaftw.music.R.drawable.ic_skip_previous_white_24dp,
                    mService.getString(com.chinaftw.music.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(com.chinaftw.music.R.drawable.ic_skip_next_white_24dp,
            mService.getString(com.chinaftw.music.R.string.label_next), mNextIntent);
    }

    MediaDescription 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(),
                com.chinaftw.music.R.drawable.ic_default_art);
        }
    }

    notificationBuilder
            .setStyle(new Notification.MediaStyle()
                .setShowActionsInCompactView(
                    new int[]{playPauseButtonPosition})  // show only play/pause in compact view
                .setMediaSession(mSessionToken))
            .setColor(mNotificationColor)
            .setSmallIcon(com.chinaftw.music.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(com.chinaftw.music.R.string.casting_to_device, castName);
            notificationBuilder.setSubText(castInfo);
            notificationBuilder.addAction(com.chinaftw.music.R.drawable.ic_close_black_24dp,
                    mService.getString(com.chinaftw.music.R.string.stop_casting), mStopCastIntent);
        }
    }

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

    return notificationBuilder.build();
}
 
开发者ID:SferaDev,项目名称:MusicFromChina,代码行数:80,代码来源:MediaNotificationManager.java


注:本文中的android.media.MediaDescription.getIconUri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。