现在玩纸牌

时间:2015-04-29 13:31:36

标签: android android-service android-5.0-lollipop android-tv

我需要有关在Recommendations行中显示正在玩牌的帮助。我在Android开发者网站上阅读了有关它的帖子,但这对我没什么帮助。

我有一项服务可以毫无问题地传输MP3数据。我添加了以下代码,但是没有正在玩牌...

@Override
public void onCreate() {
    Log.i(TAG, "onCreate called");

    mSession = new MediaSession(this, "MusicService");
    mSession.setCallback(new MediaSessionCallback());
    mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
            MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

    mSession.setActive(true);
}


private class MediaSessionCallback extends MediaSession.Callback {
}


修改:添加了元数据代码:

@Override
public void onCreate() {
    Log.i(TAG, "onCreate called");

    mSession = new MediaSession(this, "MusicService");
    mSession.setCallback(new MediaSessionCallback());
    mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
            MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);


    final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();

    String title = "Burak";

    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE,
            "Burak müzik");
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI,
            "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/Zeitgeist/Zeitgeist%202010_%20Year%20in%20Review/card.jpg");

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

    mSession.setMetadata(metadataBuilder.build());

    mSession.setActive(true);


}

2 个答案:

答案 0 :(得分:1)

我想说你需要通过Metadata.Builder类为当前播放的MP3文件指定元数据:

MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();
metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE,
        "Title");
metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE,
        "Subtitle");
metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI,
        "Artwork");
mSession.setMetadata(metadataBuilder.build());

答案 1 :(得分:0)

这可能为时已晚,无法帮助OP,但如果有人遇到此页面,我想分享一个可能的答案。您应该确保在某个时刻调用mSession.setPlayBackState(state)。例如,尝试做这样的事情开始:

            mediaSession.setMetadata(builder.build());
        PlaybackState state = new PlaybackState.Builder()
                .setActions(
                        PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState
                                .ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_REWIND |
                                PlaybackState.ACTION_FAST_FORWARD)
                .setState(PlaybackState.STATE_NONE, 0, 1.0f)
                .build();
        mediaSession.setPlaybackState(state);

您需要根据自己的需要调整操作。我的猜测是你以后设置状态,这就是为什么你注意到它在后续尝试返回主屏幕时有效。