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


Java MediaMetadata类代码示例

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


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

示例1: updateNowPlayingMetadata

import android.media.MediaMetadata; //导入依赖的package包/类
/**
 * Update title and pic on now playing card
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void updateNowPlayingMetadata() {
    MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();
    String title = mVideoInfo.scraperTitle!=null?mVideoInfo.scraperTitle:mVideoInfo.title!=null?mVideoInfo.title:Utils.getFileNameWithoutExtension(mUri);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE,
            title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE,title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI,
            mVideoInfo.scraperCover);
    Bitmap bitmap = BitmapFactory.decodeFile(mVideoInfo.scraperCover);
    if (bitmap == null&&mVideoInfo.id >= 0) { //if no scrapped poster, try to get a thumbnail
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 2;
        bitmap = VideoStore.Video.Thumbnails.getThumbnail(getContentResolver(),mVideoInfo.id, VideoStore.Video.Thumbnails.MINI_KIND, options);
    }
    if (bitmap == null) {
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.widget_default_video);
    }
    metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
    mSession.setMetadata(metadataBuilder.build());
}
 
开发者ID:archos-sa,项目名称:aos-Video,代码行数:25,代码来源:PlayerService.java

示例2: updateMediaSession

import android.media.MediaMetadata; //导入依赖的package包/类
private void updateMediaSession(int state) {

        MediaMetadata.Builder mediaBuilder = null;

        Bitmap bitmap = null;
        try {
            URL url = new URL(mRadioIcon);
            bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        } catch (IOException e) {
            Log.e(TAG, "BitmapFactory.decodeStream", e);
        }

        mediaBuilder = new MediaMetadata.Builder();
        mediaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, mTitle);
        if (bitmap != null) {
            mediaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
        }

        mMediaSession.setMetadata(mediaBuilder.build());

        PlaybackState.Builder stateBuilder = new PlaybackState.Builder();
        stateBuilder.setState(state, 0, 1.0f);

        mMediaSession.setPlaybackState(stateBuilder.build());
    }
 
开发者ID:bertrandmartel,项目名称:webradio-tv-app,代码行数:26,代码来源:RadioSingleton.java

示例3: updateMetadata

import android.media.MediaMetadata; //导入依赖的package包/类
private void updateMetadata(final Movie movie) {
    final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();

    String title = movie.getTitle().replace("_", " -");

    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE,
            movie.getDescription());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI,
            movie.getCardImageUrl());

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

    Glide.with(this)
            .load(Uri.parse(movie.getCardImageUrl()))
            .asBitmap()
            .into(new SimpleTarget<Bitmap>(500, 500) {
                @Override
                public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                    metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
                    mSession.setMetadata(metadataBuilder.build());
                }
            });
}
 
开发者ID:cleaninsights,项目名称:cleaninsights-android-sdk,代码行数:27,代码来源:PlaybackOverlayActivity.java

示例4: onMetadataChanged

import android.media.MediaMetadata; //导入依赖的package包/类
@Override
public void onMetadataChanged(MediaMetadata metadata) {
    super.onMetadataChanged(metadata);

    if (metadata != null) {
        mDevice.write(mediaArtistCharac,
                getTextAsBytes(metadata, MediaMetadata.METADATA_KEY_ARTIST),
                MediaService.this);

        mDevice.write(mediaAlbumCharac,
                getTextAsBytes(metadata, MediaMetadata.METADATA_KEY_ALBUM),
                MediaService.this);

        mDevice.write(mediaTitleCharac,
                getTextAsBytes(metadata, MediaMetadata.METADATA_KEY_TITLE),
                MediaService.this);
    }
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:19,代码来源:MediaService.java

示例5: updateMediaMetadata

import android.media.MediaMetadata; //导入依赖的package包/类
private void updateMediaMetadata(final long programId, final String title,
        final String subtitle, final long duration,
        final Bitmap posterArt, final int imageResId) {
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... arg0) {
            MediaMetadata.Builder builder = new MediaMetadata.Builder();
            builder.putLong(MediaMetadata.METADATA_KEY_MEDIA_ID, programId)
                    .putString(MediaMetadata.METADATA_KEY_TITLE, title)
                    .putLong(MediaMetadata.METADATA_KEY_DURATION, duration);
            if (subtitle != null) {
                builder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, subtitle);
            }
            Bitmap programPosterArt = posterArt;
            if (programPosterArt == null && imageResId != 0) {
                programPosterArt =
                        BitmapFactory.decodeResource(mActivity.getResources(), imageResId);
            }
            if (programPosterArt != null) {
                builder.putBitmap(MediaMetadata.METADATA_KEY_ART, programPosterArt);
            }
            mMediaSession.setMetadata(builder.build());
            return null;
        }
    }.execute();
}
 
开发者ID:trevd,项目名称:android_packages_apps_tv,代码行数:27,代码来源:DvrPlaybackMediaSessionHelper.java

示例6: fromMediaMetadata

import android.media.MediaMetadata; //导入依赖的package包/类
@Test
public void fromMediaMetadata() {
  MediaMetadata input =
      new MediaMetadata.Builder()
          .putString(MediaMetadata.METADATA_KEY_TITLE, "Title")
          .putString(MediaMetadata.METADATA_KEY_ARTIST, "Artist")
          .putString(MediaMetadata.METADATA_KEY_ALBUM, "Album")
          .putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, "Album Artist")
          .putBitmap(MediaMetadata.METADATA_KEY_ART, EMPTY_BITMAP)
          .putLong(MediaMetadata.METADATA_KEY_DURATION, 10000)
          .build();

  Track output = Track.fromMediaMetadata(input);

  assertThat(output.track()).isEqualTo("Title");
  assertThat(output.artist()).isEqualTo("Artist");
  assertThat(output.albumArtist()).hasValue("Album Artist");
  assertThat(output.art()).isPresent();
  assertThat(output.duration()).hasValue((long) 10000);
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:21,代码来源:TrackTest.java

示例7: fromMediaMetadata_generatesInvalidTrackWhenNoArtistOrTitle

import android.media.MediaMetadata; //导入依赖的package包/类
@Test
public void fromMediaMetadata_generatesInvalidTrackWhenNoArtistOrTitle() {
  MediaMetadata empty = new MediaMetadata.Builder().build();
  MediaMetadata noTitle =
      new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_ARTIST, "Artist").build();
  MediaMetadata noArtist =
      new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_TITLE, "Title").build();

  Track output1 = Track.fromMediaMetadata(empty);
  Track output2 = Track.fromMediaMetadata(noTitle);
  Track output3 = Track.fromMediaMetadata(noArtist);

  assertThat(output1.isValid()).isFalse();
  assertThat(output2.isValid()).isFalse();
  assertThat(output3.isValid()).isFalse();
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:17,代码来源:TrackTest.java

示例8: fromMediaMetadata_translatesShortDurationsToMilliseconds

import android.media.MediaMetadata; //导入依赖的package包/类
@Test
public void fromMediaMetadata_translatesShortDurationsToMilliseconds() {
  long threeMinutesSeconds = 4 * 60;
  long threeMinutesMs = 4 * 60 * 1000;
  MediaMetadata millisecondsInput =
      new MediaMetadata.Builder()
          .putLong(MediaMetadata.METADATA_KEY_DURATION, threeMinutesMs)
          .build();
  MediaMetadata secondsInput =
      new MediaMetadata.Builder()
          .putLong(MediaMetadata.METADATA_KEY_DURATION, threeMinutesSeconds)
          .build();

  Track output1 = Track.fromMediaMetadata(millisecondsInput);
  Track output2 = Track.fromMediaMetadata(secondsInput);

  assertThat(output1.duration()).hasValue(threeMinutesMs);
  assertThat(output2.duration()).hasValue(threeMinutesMs);
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:20,代码来源:TrackTest.java

示例9: updateMediaSessionMetaData

import android.media.MediaMetadata; //导入依赖的package包/类
private void updateMediaSessionMetaData() {
    if (mCurrentMediaItem == null) {
        throw new IllegalArgumentException(
                "mCurrentMediaItem is null in updateMediaSessionMetaData!");
    }
    MediaMetadataCompat.Builder metaDataBuilder = new MediaMetadataCompat.Builder();
    if (mCurrentMediaItem.getMediaTitle() != null) {
        metaDataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE,
                mCurrentMediaItem.getMediaTitle());
    }
    if (mCurrentMediaItem.getMediaAlbumName() != null) {
        metaDataBuilder.putString(MediaMetadata.METADATA_KEY_ALBUM,
                mCurrentMediaItem.getMediaAlbumName());
    }
    if (mCurrentMediaItem.getMediaArtistName() != null) {
        metaDataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST,
                mCurrentMediaItem.getMediaArtistName());
    }
    if (mCurrentMediaItem.getMediaAlbumArtResId() != 0) {
        Bitmap albumArtBitmap = BitmapFactory.decodeResource(getResources(),
                mCurrentMediaItem.getMediaAlbumArtResId());
        metaDataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, albumArtBitmap);
    }
    mMediaSession.setMetadata(metaDataBuilder.build());
}
 
开发者ID:googlesamples,项目名称:leanback-showcase,代码行数:26,代码来源:MusicPlaybackService.java

示例10: onCustomAction

import android.media.MediaMetadata; //导入依赖的package包/类
@Override
public void onCustomAction(@NonNull String action, Bundle extras) {
    if (CUSTOM_ACTION_THUMBS_UP.equals(action)) {
        LogHelper.i(TAG, "onCustomAction: favorite for current track");
        MediaMetadata track = getCurrentPlayingMusic();
        if (track != null) {
            String musicId = track.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
            mMusicProvider.setFavorite(musicId, !mMusicProvider.isFavorite(musicId));
        }
        // playback state needs to be updated because the "Favorite" icon on the
        // custom action will change to reflect the new favorite state.
        updatePlaybackState(null);
    } else {
        LogHelper.e(TAG, "Unsupported action: ", action);
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:17,代码来源:MusicService.java

示例11: setCustomAction

import android.media.MediaMetadata; //导入依赖的package包/类
private void setCustomAction(PlaybackState.Builder stateBuilder) {
    MediaMetadata currentMusic = getCurrentPlayingMusic();
    if (currentMusic != null) {
        // Set appropriate "Favorite" icon on Custom action:
        String musicId = currentMusic.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
        int favoriteIcon = R.drawable.ic_star_off;
        if (mMusicProvider.isFavorite(musicId)) {
            favoriteIcon = R.drawable.ic_star_on;
        }
        LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ",
                musicId, " current favorite=", mMusicProvider.isFavorite(musicId));
        Bundle customActionExtras = new Bundle();
        WearHelper.setShowCustomActionOnWear(customActionExtras, true);
        stateBuilder.addCustomAction(new PlaybackState.CustomAction.Builder(
                CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite), favoriteIcon)
                .setExtras(customActionExtras)
                .build());
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:20,代码来源:MusicService.java

示例12: convertToQueue

import android.media.MediaMetadata; //导入依赖的package包/类
private static List<MediaSession.QueueItem> convertToQueue(
        Iterable<MediaMetadata> tracks, String... categories) {
    List<MediaSession.QueueItem> queue = new ArrayList<>();
    int count = 0;
    for (MediaMetadata track : tracks) {

        // We create a hierarchy-aware mediaID, so we know what the queue is about by looking
        // at the QueueItem media IDs.
        String hierarchyAwareMediaID = MediaIDHelper.createMediaID(
                track.getDescription().getMediaId(), categories);

        MediaMetadata trackCopy = new MediaMetadata.Builder(track)
                .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID)
                .build();

        // We don't expect queues to change after created, so we use the item index as the
        // queueId. Any other number unique in the queue would work.
        MediaSession.QueueItem item = new MediaSession.QueueItem(
                trackCopy.getDescription(), count++);
        queue.add(item);
    }
    return queue;

}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:25,代码来源:QueueHelper.java

示例13: getRandomQueue

import android.media.MediaMetadata; //导入依赖的package包/类
/**
 * Create a random queue.
 *
 * @param musicProvider the provider used for fetching music.
 * @return list containing {@link MediaSession.QueueItem}'s
 */
public static List<MediaSession.QueueItem> getRandomQueue(MusicProvider musicProvider) {
    List<MediaMetadata> result = new ArrayList<>();

    for (String genre: musicProvider.getGenres()) {
        Iterable<MediaMetadata> tracks = musicProvider.getMusicsByGenre(genre);
        for (MediaMetadata track: tracks) {
            if (ThreadLocalRandom.current().nextBoolean()) {
                result.add(track);
            }
        }
    }
    LogHelper.d(TAG, "getRandomQueue: result.size=", result.size());

    Collections.shuffle(result);

    return convertToQueue(result, MEDIA_ID_MUSICS_BY_SEARCH, "random");
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:24,代码来源:QueueHelper.java

示例14: updateMusic

import android.media.MediaMetadata; //导入依赖的package包/类
public synchronized void updateMusic(String musicId, MediaMetadata metadata) {
    MutableMediaMetadata track = mMusicListById.get(musicId);
    if (track == null) {
        return;
    }

    String oldGenre = track.metadata.getString(MediaMetadata.METADATA_KEY_GENRE);
    String newGenre = metadata.getString(MediaMetadata.METADATA_KEY_GENRE);

    track.metadata = metadata;

    // if genre has changed, we need to rebuild the list by genre
    if (!oldGenre.equals(newGenre)) {
        buildListsByGenre();
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:17,代码来源:MusicProvider.java

示例15: addPlaybackControlsRow

import android.media.MediaMetadata; //导入依赖的package包/类
private void addPlaybackControlsRow(MediaMetadata metadata) {

        mPlaybackControlsRow = new PlaybackControlsRow(new MutableMediaMetadataHolder(metadata));
        mRowsAdapter.add(mPlaybackControlsRow);

        resetPlaybackRow();

        ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector();
        mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector);
        mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter);

        mPlayPauseAction = new PlayPauseAction(getActivity());
        mSkipNextAction = new PlaybackControlsRow.SkipNextAction(getActivity());
        mSkipPreviousAction = new PlaybackControlsRow.SkipPreviousAction(getActivity());

        mPrimaryActionsAdapter.add(mSkipPreviousAction);
        mPrimaryActionsAdapter.add(mPlayPauseAction);
        mPrimaryActionsAdapter.add(mSkipNextAction);
    }
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:20,代码来源:TvPlaybackFragment.java


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