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


Java MediaMetadataCompat.Builder方法代码示例

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


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

示例1: notifyAyahChanged

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
private void notifyAyahChanged() {
  if (mAudioRequest != null) {
    Intent updateIntent = new Intent(AudioUpdateIntent.INTENT_NAME);
    updateIntent.putExtra(AudioUpdateIntent.STATUS, AudioUpdateIntent.PLAYING);
    updateIntent.putExtra(AudioUpdateIntent.SURA, mAudioRequest.getCurrentSura());
    updateIntent.putExtra(AudioUpdateIntent.AYAH, mAudioRequest.getCurrentAyah());
    mBroadcastManager.sendBroadcast(updateIntent);

    MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder()
        .putString(MediaMetadataCompat.METADATA_KEY_TITLE, mAudioRequest.getTitle(this));
    if (mPlayer.isPlaying()) {
      metadataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, mPlayer.getDuration());
    }

    if (mDisplayIcon != null) {
      metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, mDisplayIcon);
    }
    mMediaSession.setMetadata(metadataBuilder.build());
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:21,代码来源:AudioService.java

示例2: updateMetaData

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
/**
 * 更新正在播放的音乐信息,切换歌曲时调用
 */
public void updateMetaData(String path) {
    if (!StringUtils.isReal(path)) {
        mMediaSession.setMetadata(null);
        return;
    }

    SongInfo info = mediaManager.getSongInfo(context, path);
    MediaMetadataCompat.Builder metaData = new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, info.getTitle())
            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, info.getArtist())
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, info.getAlbum())
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, info.getArtist())
            .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getDuration())
            .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, getCoverBitmap(info));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        metaData.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getCount());
    }

    mMediaSession.setMetadata(metaData.build());
}
 
开发者ID:DuanJiaNing,项目名称:Musicoco,代码行数:25,代码来源:MediaSessionManager.java

示例3: updateMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
public void updateMetadata(String trackTitle, String artist, String album, BitmapDrawable albumImage) {
    MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album)
            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, trackTitle)
            .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, -1);
    if (albumImage != null) {
        metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumImage.getBitmap());
    }
    mediaSession.setMetadata(metadataBuilder.build());
    mediaSession.setActive(true);

    // Put the service in the foreground, post notification
    Helpers.createStopNotification(mediaSession, MediaRecorderService.this, MediaRecorderService.class, NOTIFICATION_ID);

    // currently, only way to update Cast metadata is to re-send URL which causes reload of stream
    //castMedia(trackTitle, artist, album, imageUrl);
}
 
开发者ID:aschober,项目名称:vinyl-cast,代码行数:19,代码来源:MediaRecorderService.java

示例4: getMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
public static MediaMetadataCompat getMetadata(Context ctx, String mediaId) {
    MediaMetadataCompat metadataWithoutBitmap = music.get(mediaId);
    Bitmap albumArt = getAlbumBitmap(ctx, mediaId);

    // Since MediaMetadataCompat is immutable, we need to create a copy to set the album art
    // We don't set it initially on all items so that they don't take unnecessary memory
    MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
    for (String key :
            new String[]{
                    MediaMetadataCompat.METADATA_KEY_MEDIA_ID,
                    MediaMetadataCompat.METADATA_KEY_ALBUM,
                    MediaMetadataCompat.METADATA_KEY_ARTIST,
                    MediaMetadataCompat.METADATA_KEY_GENRE,
                    MediaMetadataCompat.METADATA_KEY_TITLE
            }) {
        builder.putString(key, metadataWithoutBitmap.getString(key));
    }
    builder.putLong(
            MediaMetadataCompat.METADATA_KEY_DURATION,
            metadataWithoutBitmap.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
    builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
    return builder.build();
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:24,代码来源:MusicLibrary.java

示例5: getMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
public static MediaMetadataCompat getMetadata(Context ctx, String mediaId) {
    MediaMetadataCompat metadataWithoutBitmap = music.get(mediaId);
    Bitmap albumArt = getAlbumBitmap(ctx, mediaId);

    // Since MediaMetadataCompat is immutable, we need to create a copy to set the album art.
    // We don't set it initially on all items so that they don't take unnecessary memory.
    MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
    for (String key :
            new String[] {
                MediaMetadataCompat.METADATA_KEY_MEDIA_ID,
                MediaMetadataCompat.METADATA_KEY_ALBUM,
                MediaMetadataCompat.METADATA_KEY_ARTIST,
                MediaMetadataCompat.METADATA_KEY_GENRE,
                MediaMetadataCompat.METADATA_KEY_TITLE
            }) {
        builder.putString(key, metadataWithoutBitmap.getString(key));
    }
    builder.putLong(
            MediaMetadataCompat.METADATA_KEY_DURATION,
            metadataWithoutBitmap.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
    builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
    return builder.build();
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:24,代码来源:MusicLibrary.java

示例6: createMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
private MediaMetadataCompat createMetadata() {
    MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE,
                mMediaNotificationInfo.metadata.getTitle());
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE,
                mMediaNotificationInfo.origin);
    } else {
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE,
                mMediaNotificationInfo.metadata.getTitle());
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST,
                mMediaNotificationInfo.origin);
    }
    if (!TextUtils.isEmpty(mMediaNotificationInfo.metadata.getArtist())) {
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST,
                mMediaNotificationInfo.metadata.getArtist());
    }
    if (!TextUtils.isEmpty(mMediaNotificationInfo.metadata.getAlbum())) {
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM,
                mMediaNotificationInfo.metadata.getAlbum());
    }

    return metadataBuilder.build();
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:26,代码来源:MediaNotificationManager.java

示例7: getMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
public static MediaMetadataCompat getMetadata(Context context, String mediaId) {
    MediaMetadataCompat metadataWithoutBitmap = music.get(mediaId);
    Bitmap albumArt = getAlbumBitmap(context, mediaId);

    // Since MediaMetadataCompat is immutable, we need to create a copy to set the album art.
    // We don't set it initially on all items so that they don't take unnecessary memory.
    MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
    for (String key :
            new String[]{
                    MediaMetadataCompat.METADATA_KEY_MEDIA_ID,
                    MediaMetadataCompat.METADATA_KEY_ALBUM,
                    MediaMetadataCompat.METADATA_KEY_ARTIST,
                    MediaMetadataCompat.METADATA_KEY_GENRE,
                    MediaMetadataCompat.METADATA_KEY_TITLE
            }) {
        builder.putString(key, metadataWithoutBitmap.getString(key));
    }
    builder.putLong(
            MediaMetadataCompat.METADATA_KEY_DURATION,
            metadataWithoutBitmap.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
    builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
    return builder.build();
}
 
开发者ID:nazmulidris,项目名称:mediasession-mediaplayer,代码行数:24,代码来源:MusicLibrary.java

示例8: getMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
public static MediaMetadataCompat getMetadata(String mediaId) {
    MediaMetadataCompat metadataWithoutBitmap = music.get(mediaId);
    Bitmap albumArt = getAlbumBitmap(mediaId);

    // Since MediaMetadataCompat is immutable, we need to create a copy to set the album art.
    // We don't set it initially on all items so that they don't take unnecessary memory.
    MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
    for (String key :
            new String[]{
                    MediaMetadataCompat.METADATA_KEY_MEDIA_ID,
                    MediaMetadataCompat.METADATA_KEY_ALBUM,
                    MediaMetadataCompat.METADATA_KEY_ARTIST,
                    MediaMetadataCompat.METADATA_KEY_GENRE,
                    MediaMetadataCompat.METADATA_KEY_TITLE
            }) {
        builder.putString(key, metadataWithoutBitmap.getString(key));
    }
    builder.putLong(
            MediaMetadataCompat.METADATA_KEY_DURATION,
            metadataWithoutBitmap.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
    builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
    return builder.build();
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:24,代码来源:LocalMusicLibrary.java

示例9: updateMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
private void updateMetadata(final Video video) {
        final MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder();

        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, video.id + "");
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, video.title);
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, video.studio);
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION,
                video.description);

        /*
        long duration = Utils.getDuration(video.videoUrl);
        metadataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration);
*/
        long duration = getDuration();
        metadataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration);

        // And at minimum the title and artist for legacy support
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, video.title);
        metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, video.studio);

        Resources res = getResources();
        int cardWidth = res.getDimensionPixelSize(R.dimen.playback_overlay_width);
        int cardHeight = res.getDimensionPixelSize(R.dimen.playback_overlay_height);

        Glide.with(this)
                .load(Uri.parse(video.cardImageUrl))
                .asBitmap()
                .centerCrop()
                .into(new SimpleTarget<Bitmap>(cardWidth, cardHeight) {
                    @Override
                    public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                        metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap);
                        mSession.setMetadata(metadataBuilder.build());
                    }
                });
    }
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:37,代码来源:PlaybackOverlayFragment.java

示例10: updateMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
private void updateMetadata(final Clip clip) {
    final MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder();

    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, clip.getTitle());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE,
            clip.getDescription());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI,
            clip.getCardImageUrl());

    // And at minimum the title and artist for legacy support
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, clip.getTitle());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, clip.getDescription());

    Glide.with(this)
            .asBitmap()
            .load(Uri.parse(clip.getCardImageUrl()))
            .into(new SimpleTarget<Bitmap>(500, 500) {
                @Override
                public void onResourceReady(Bitmap bitmap, Transition transition) {
                    metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
                    mSession.setMetadata(metadataBuilder.build());
                }

                @Override
                public void onLoadFailed(Drawable errorDrawable) {
                    Log.e(TAG, "onLoadFailed: " + errorDrawable);
                    mSession.setMetadata(metadataBuilder.build());
                }
            });
}
 
开发者ID:googlesamples,项目名称:leanback-homescreen-channels,代码行数:31,代码来源:VideoFragment.java

示例11: updateMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
private void updateMetadata(final Video video) {
    final MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder();

    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, video.id + "");
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, video.title);
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, video.studio);
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION,
            video.description);

    long duration = Utils.getDuration(video.videoUrl);
    metadataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration);

    // And at minimum the title and artist for legacy support
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, video.title);
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, video.studio);

    Resources res = getResources();
    int cardWidth = res.getDimensionPixelSize(R.dimen.playback_overlay_width);
    int cardHeight = res.getDimensionPixelSize(R.dimen.playback_overlay_height);

    Glide.with(this)
            .load(Uri.parse(video.cardImageUrl))
            .asBitmap()
            .centerCrop()
            .into(new SimpleTarget<Bitmap>(cardWidth, cardHeight) {
                @Override
                public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                    metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap);
                    mSession.setMetadata(metadataBuilder.build());
                }
            });
}
 
开发者ID:ad-on-is,项目名称:chilly,代码行数:33,代码来源:PlaybackOverlayFragment.java

示例12: mapToMetadata

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
/**
 * Converts a {@link MediaDescriptionCompat} into {@link MediaMetadataCompat}. Only a title,
 * description, and media id will be converted. A subclass should override this method if their
 * {@link #map(Object)} method stores more data in the mapped MediaDescriptionCompat.
 *
 * @param item to be converted.
 * @return A converted MediaMetadataCompact from MediaDescriptionCompat.
 */
@NonNull
public MediaMetadataCompat mapToMetadata(MediaDescriptionCompat item) {
    MediaMetadataCompat.Builder builder =
            new MediaMetadataCompat.Builder()
                    .putText(MediaMetadataCompat.METADATA_KEY_TITLE, item.getTitle())
                    .putText(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, item.getTitle())
                    .putText(
                            MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION,
                            item.getDescription())
                    .putBitmap(
                            MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, item.getIconBitmap())
                    .putText(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, item.getMediaId());

    if (item.getIconUri() != null) {
        builder.putString(
                MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI,
                item.getIconUri().toString());
    }

    Bundle extras = item.getExtras();
    if (extras != null) {
        String backgroundArtUri = extras.getString(EXTRA_BACKGROUND_ART);
        if (backgroundArtUri != null) {
            builder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, backgroundArtUri);
        }
    }

    return builder.build();
}
 
开发者ID:googlesamples,项目名称:leanback-assistant,代码行数:38,代码来源:ListPlaylistAdapter.java

示例13: updateMediaSessionMetaData

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
private void updateMediaSessionMetaData() {
    final Song song = getCurrentSong();

    if (song.id == -1) {
        mediaSession.setMetadata(null);
        return;
    }

    final MediaMetadataCompat.Builder metaData = new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.artistName)
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, song.artistName)
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, song.albumName)
            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.title)
            .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, song.duration)
            .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, getPosition() + 1)
            .putLong(MediaMetadataCompat.METADATA_KEY_YEAR, song.year)
            .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        metaData.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getPlayingQueue().size());
    }

    if (PreferenceUtil.getInstance(this).albumArtOnLockscreen()) {
        final Point screenSize = Util.getScreenSize(MusicService.this);
        final BitmapRequestBuilder<?, Bitmap> request = SongGlideRequest.Builder.from(Glide.with(MusicService.this), song)
                .checkIgnoreMediaStore(MusicService.this)
                .asBitmap().build();
        if (PreferenceUtil.getInstance(this).blurredAlbumArt()) {
            request.transform(new BlurTransformation.Builder(MusicService.this).build());
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                request.into(new SimpleTarget<Bitmap>(screenSize.x, screenSize.y) {
                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        super.onLoadFailed(e, errorDrawable);
                        mediaSession.setMetadata(metaData.build());
                    }

                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, copy(resource));
                        mediaSession.setMetadata(metaData.build());
                    }
                });
            }
        });
    } else {
        mediaSession.setMetadata(metaData.build());
    }
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:53,代码来源:MusicService.java

示例14: playFromUri

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
public void playFromUri(Uri uri, Bundle bundle) {
    mPlayOnFocusGain = true;
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();

    mState = PlaybackStateCompat.STATE_STOPPED;
    relaxResources(true);

    try {
        createMediaPlayerIfNeeded();

        mState = PlaybackStateCompat.STATE_BUFFERING;
        mCurrentPosition = 0;

        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setDataSource(uri.toString());

        // Starts preparing the media player in the background. When
        // it's done, it will call our OnPreparedListener (that is,
        // the onPrepared() method on this class, since we set the
        // listener to 'this'). Until the media player is prepared,
        // we *cannot* call start() on it!
        mMediaPlayer.prepareAsync();

        // If we are streaming from the internet, we want to hold a
        // Wifi lock, which prevents the Wifi radio from going to
        // sleep while the song is playing.
        mWifiLock.acquire();

        if (mCallback != null) {
            mCallback.onPlaybackStateChanged(mState);

            MediaMetadataCompat.Builder metaBuilder = new MediaMetadataCompat.Builder();
            metaBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, bundle.getString(MediaMetadataCompat.METADATA_KEY_ARTIST));
            metaBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, bundle.getString(MediaMetadataCompat.METADATA_KEY_TITLE));
            metaBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, bundle.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI));
            mCallback.onMediaMetadataChanged(metaBuilder.build());
        }

    } catch (IOException ex) {
        Log.e(TAG, ex +  "Exception playing song");
        if (mCallback != null) {
            mCallback.onError(ex.getMessage());
        }
    }
}
 
开发者ID:AllThatSeries,项目名称:react-native-streaming-audio-player,代码行数:47,代码来源:Playback.java

示例15: setBitmapForLockScreen

import android.support.v4.media.MediaMetadataCompat; //导入方法依赖的package包/类
private void setBitmapForLockScreen(MediaInfo video) {
    if (video == null || mMediaSessionCompat == null) {
        return;
    }
    Uri imgUrl = null;
    Bitmap bm = null;
    List<WebImage> images = video.getMetadata().getImages();
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (images.size() > 1) {
            imgUrl = images.get(1).getUrl();
        } else if (images.size() == 1) {
            imgUrl = images.get(0).getUrl();
        } else if (mContext != null) {
            // we don't have a url for image so get a placeholder image from resources
            bm = BitmapFactory.decodeResource(mContext.getResources(),
                    R.drawable.album_art_placeholder_large);
        }
    } else if (!images.isEmpty()) {
        imgUrl = images.get(0).getUrl();
    } else {
        // we don't have a url for image so get a placeholder image from resources
        bm = BitmapFactory.decodeResource(mContext.getResources(),
                R.drawable.album_art_placeholder);
    }
    if (bm != null) {
        MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
        MediaMetadataCompat.Builder newBuilder = currentMetadata == null
                ? new MediaMetadataCompat.Builder()
                : new MediaMetadataCompat.Builder(currentMetadata);
        mMediaSessionCompat.setMetadata(newBuilder
                .putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bm)
                .build());
    } else {
        if (mLockScreenFetchTask != null) {
            mLockScreenFetchTask.cancel(true);
        }
        Point screenSize = Utils.getDisplaySize(mContext);
        mLockScreenFetchTask = new FetchBitmapTask(screenSize.x, screenSize.y, false) {
            @Override
            protected void onPostExecute(Bitmap bitmap) {
                if (bitmap != null && mMediaSessionCompat != null) {
                    MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController()
                            .getMetadata();
                    MediaMetadataCompat.Builder newBuilder = currentMetadata == null
                            ? new MediaMetadataCompat.Builder()
                            : new MediaMetadataCompat.Builder(currentMetadata);
                    mMediaSessionCompat.setMetadata(newBuilder
                            .putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
                            .build());
                }
                mLockScreenFetchTask = null;
            }
        };
        mLockScreenFetchTask.execute(imgUrl);
    }
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:57,代码来源:VideoCastManager.java


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