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


Java MediaMetadataCompat类代码示例

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


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

示例1: createNotification

import android.support.v4.media.MediaMetadataCompat; //导入依赖的package包/类
private Notification createNotification(){
    if(mediaMetadata==null||playbackState==null) return null;
    NotificationCompat.Builder builder=new NotificationCompat.Builder(service);
    builder.setStyle(new  NotificationCompat.MediaStyle()
            .setMediaSession(token)
            .setShowActionsInCompactView(1))
            .setColor(Color.WHITE)
            .setPriority(Notification.PRIORITY_MAX)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setUsesChronometer(true)
            .setDeleteIntent(dismissedNotification(service))
            .setSmallIcon(R.drawable.ic_music_note)
            .setContentIntent(contentIntent(service))
            .setContentTitle(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST))
            .setContentText(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE))
            .addAction(prev(service));
    if(playbackState.getState()==PlaybackStateCompat.STATE_PLAYING){
        builder.addAction(pause(service));
    }else{
        builder.addAction(play(service));
    }
    builder.addAction(next(service));
    setNotificationPlaybackState(builder);
    loadImage(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI),builder);
    return builder.build();
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:27,代码来源:TrackNotification.java

示例2: initializeMediaSession

import android.support.v4.media.MediaMetadataCompat; //导入依赖的package包/类
private void initializeMediaSession() {
    mSession = new MediaSessionCompat(this, TAG);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                    | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mSession.setActive(true);
    MediaControllerCompat.setMediaController(this, mSession.getController());

    MediaMetadataCompat metadata = new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mMovieView.getTitle())
            .build();
    mSession.setMetadata(metadata);

    MediaSessionCallback mMediaSessionCallback = new MediaSessionCallback(mMovieView);
    mSession.setCallback(mMediaSessionCallback);

    int state =
            mMovieView.isPlaying()
                    ? PlaybackStateCompat.STATE_PLAYING
                    : PlaybackStateCompat.STATE_PAUSED;
    updatePlaybackState(
            state,
            MEDIA_ACTIONS_ALL,
            mMovieView.getCurrentPosition(),
            mMovieView.getVideoResourceId());
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:27,代码来源:MediaSessionPlaybackActivity.java

示例3: updateRemoteControlClient

import android.support.v4.media.MediaMetadataCompat; //导入依赖的package包/类
/**
 * Updates the lockscreen controls.
 *
 * @param what The broadcast
 */
private void updateRemoteControlClient(final String what) {
    int playState = isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
    PlaybackStateCompat pmc = new PlaybackStateCompat.Builder()
            .setState(playState, position(), 1.0f)
            .setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)
            .build();
    switch (what) {
        case PLAYSTATE_CHANGED:
        case POSITION_CHANGED:
            mMediaSession.setPlaybackState(pmc);
            break;
        case META_CHANGED:
            mMediaSession.setMetadata(new MediaMetadataCompat.Builder()
                    .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getArtistName())
                    .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getAlbumName())
                    .putString(MediaMetadataCompat.METADATA_KEY_TITLE, getTrackName())
                    //.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, getAlbumCover())
                    .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration())
                    .build());

            break;
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:29,代码来源:MusicPlaybackService.java

示例4: 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

示例5: 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

示例6: 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

示例7: getMetadata

import android.support.v4.media.MediaMetadataCompat; //导入依赖的package包/类
private MediaMetadataCompat getMetadata(Context context, Station station, String metaData) {
    Bitmap stationImage = null;
    // try to get station image
    if (station != null && station.getStationImageFile() != null && station.getStationImageFile().exists()) {
        stationImage = BitmapFactory.decodeFile(station.getStationImageFile().toString());
    }
    // use name of app as album title
    String albumTitle = context.getResources().getString(R.string.app_name);

    // log metadata change
    LogHelper.v(LOG_TAG, "New Metadata available.");

    if (station != null) {
        return new MediaMetadataCompat.Builder()
                .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, station.getStationName())
                .putString(MediaMetadataCompat.METADATA_KEY_TITLE, metaData)
                .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, albumTitle)
                .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, stationImage)
                .build();
    } else {
        return null;
    }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:24,代码来源:PlayerService.java

示例8: getMetadata

import android.support.v4.media.MediaMetadataCompat; //导入依赖的package包/类
private MediaMetadataCompat getMetadata(Context context, Station station, String metaData) {
    Bitmap stationImage;

    File imageFileRef = station.getStationImage(context);
    if (imageFileRef != null && imageFileRef.exists()) {
        // use station image
        stationImage = BitmapFactory.decodeFile(imageFileRef.toString());
    } else {
        stationImage = null;
    }
    // use name of app as album title
    String albumTitle = context.getResources().getString(R.string.app_name);

    // log metadata change
    LogHelper.i(LOG_TAG, "New Metadata available. Artist: " + station.TITLE + ", Title: " + metaData + ", Album: " + albumTitle);

    return new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, station.TITLE)
            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, metaData)
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, albumTitle)
            .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, stationImage)
            .build();
}
 
开发者ID:malah-code,项目名称:Open-Quran-Radio,代码行数:24,代码来源:PlayerService.java

示例9: 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

示例10: onMetadataChanged

import android.support.v4.media.MediaMetadataCompat; //导入依赖的package包/类
@Override
public void onMetadataChanged(final MediaMetadataCompat metadata) {
    // Filtering out needless updates, given that the metadata has not changed.
    if (isMediaIdSame(metadata, mState.getMediaMetadata())) {
        Log.d(TAG, "onMetadataChanged: Filtering out needless onMetadataChanged() update");
        return;
    } else {
        mState.setMediaMetadata(metadata);
    }
    performOnAllListeners(new ListenerCommand() {
        @Override
        public void perform(@NonNull MediaBrowserChangeListener listener) {
            listener.onMetadataChanged(metadata);
        }
    });
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:17,代码来源:MediaBrowserManager.java

示例11: cloneMetadataIfNeeded

import android.support.v4.media.MediaMetadataCompat; //导入依赖的package包/类
private MediaMetadataCompat cloneMetadataIfNeeded(MediaMetadataCompat metadata) {
    if (metadata == null) {
        return null;
    }
    if (!metadata.containsKey(MediaMetadataCompat.METADATA_KEY_ART) && !metadata.containsKey(MediaMetadataCompat.METADATA_KEY_ALBUM_ART)) {
        return metadata;
    }
    Builder builder = new Builder(metadata);
    Bitmap artBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ART);
    if (artBitmap != null) {
        builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, artBitmap.copy(artBitmap.getConfig(), false));
    }
    Bitmap albumArtBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART);
    if (albumArtBitmap != null) {
        builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArtBitmap.copy(albumArtBitmap.getConfig(), false));
    }
    return builder.build();
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:MediaSessionCompat.java

示例12: iterator

import android.support.v4.media.MediaMetadataCompat; //导入依赖的package包/类
@Override
public Iterator<MediaMetadataCompat> iterator(Context context) {
    ContentResolver mResolver = context.getContentResolver();
    ArrayList<Album> albums = MediaStoreHelper.loadAlbumList(mResolver, null, null, MediaStore.Audio.Albums.ALBUM);
    ArrayList<Track> tracks = MediaStoreHelper.loadTrackList(mResolver, null, null, MediaStore.Audio.Media.TITLE);
    ArrayList<MediaMetadataCompat> mediaList = new ArrayList<>();
    for (Track track: tracks) {
        for (Album album: albums) {
            if (track.getAlbumId() == album.getId()) {
                track.setAlbum(album);
            }
        }
        mediaList.add(buildMediaFromTrack(track));
    }

    Collections.sort(mediaList, new Comparator<MediaMetadataCompat>() {
        @Override
        public int compare(MediaMetadataCompat m1, MediaMetadataCompat m2) {
            String titleOfM1 = m1.getString(MediaMetadataCompat.METADATA_KEY_TITLE);
            String titleOfM2 = m2.getString(MediaMetadataCompat.METADATA_KEY_TITLE);
            return titleOfM1.compareTo(titleOfM2);
        }
    });

    return mediaList.iterator();
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:27,代码来源:LocalMusicSource.java

示例13: 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

示例14: 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

示例15: 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


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