小编tok*_*udu的帖子

MediaStyle通知未响应RemoteControl事件.

我们正在将正在进行的播放通知迁移到Lollipop中引入的MediaStyle通知.RemoteControlClient似乎已被弃用,MediaStyle通知不处理媒体按钮事件(例如通过耳机远程暂停/播放).

有没有人得到这个工作?MediaSessionCallback中没有任何事件被调用.

以下是媒体会话的初始化方式

    mSession = new MediaSessionCompat(this, TAG);
    mSession.setCallback(new MediaSessionCallback());
    mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC);
    mSession.setActive(true);
Run Code Online (Sandbox Code Playgroud)

以下是设置元数据的方式

    MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder();
    metadataBuilder
            .putLong(MediaMetadata.METADATA_KEY_DURATION, clip.getDuration())
            .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, clip.getClipId())
            .putString(MediaMetadata.METADATA_KEY_TITLE, clip.getTitle())
            .putString(MediaMetadata.METADATA_KEY_ARTIST, clip.getSourceName())
            .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, clip.getImageUrl())
            .putLong(MediaMetadata.METADATA_KEY_DURATION, clip.getDuration());
    mSession.setMetadata(metadataBuilder.build());
Run Code Online (Sandbox Code Playgroud)

最后,通知代码:

        MediaSession mediaSession = (MediaSession) session.getMediaSession();
        Notification.Builder builder =
                new Notification.Builder(c)
                        .setDefaults(0)
                        .setSmallIcon(R.drawable.ic_notif)
                        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                        .setContentTitle(clip.getTitle())
                        .setContentText(clip.getSourceName())
                        .setProgress((int)duration, (int)progress, false)
                        .setWhen(0)
                        .setContentIntent(pendingIntent);

        if (playing) {
            builder.addAction(R.drawable.ic_media_pause, c.getString(R.string.media_pause),
                    getPendingIntentForKeyCode(app.getApplicationContext(), KeyEvent.KEYCODE_MEDIA_PAUSE));
        } else {
            builder.addAction(R.drawable.ic_media_play, c.getString(R.string.media_play),
                    getPendingIntentForKeyCode(app.getApplicationContext(), KeyEvent.KEYCODE_MEDIA_PLAY));
        }
        builder.addAction(R.drawable.ic_media_next, c.getString(R.string.media_next),
                    getPendingIntentForKeyCode(app.getApplicationContext(), KeyEvent.KEYCODE_MEDIA_NEXT));

        builder.setStyle(new Notification.MediaStyle()
                .setMediaSession(mediaSession.getSessionToken())
                .setShowActionsInCompactView(new int[] …
Run Code Online (Sandbox Code Playgroud)

android android-5.0-lollipop

7
推荐指数
1
解决办法
3002
查看次数

添加两个具有不同主题的AppCompat工具栏

我想在我的应用程序中有两个不同的android.support.v7.widget.Toolbars,一个黑暗,一个灯,并在需要时在它们之间切换.但是,当我在第二个工具栏上设置不同的主题时,它似乎也重置了第一个工具栏上的主题.

这是一个错误或预期的行为?

工具栏1:

<android.support.v7.widget.Toolbar
xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_gravity="top"
android:background="@drawable/action_bar_background"
sothree:theme="@style/ThemeOverlay.AppCompat.ActionBar"
sothree:contentInsetStart="0dp"/>
Run Code Online (Sandbox Code Playgroud)

工具栏2:

<android.support.v7.widget.Toolbar
xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/clip_toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_gravity="top"
android:background="@android:color/transparent"
sothree:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
sothree:popupTheme="@style/ThemeOverlay.AppCompat.Light"
sothree:contentInsetStart="0dp"/>
Run Code Online (Sandbox Code Playgroud)

android android-5.0-lollipop android-toolbar

5
推荐指数
1
解决办法
2497
查看次数