2

我遇到了 5.0 MediaSession 控件的问题。我的应用程序流式传输现场音乐,所以我不使用暂停按钮,只使用停止按钮。我无法弄清楚如何只在我的穿戴设备上显示一个停止按钮......停止按钮显示并从我手机上的通知中正常工作......但在 Moto360 上只显示标准暂停/播放切换。当我覆盖 onPause() 时,我可以从手表中获得正确的行为,但我想在 MediaSession 回调中使用 onStop()。我不想通过显示暂停按钮来混淆我的用户。

private void buildNotification(Notification.Action action)
{
    Notification.MediaStyle style = new Notification.MediaStyle();
    style.setMediaSession(mSession.getSessionToken());
    style.setShowActionsInCompactView(0);

    Intent intent = new Intent(getApplicationContext(), Play.class);
    intent.setAction(ACTION_STOP);

    if ((selectedUrl.equals(MouseWorldRadioActivity.radioFiveIP)) || (selectedUrl.equals(MouseWorldRadioActivity.scrIP)))
        {
            PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,                
            new Intent(getApplicationContext(), nowPlaying.class),0);

            Notification.Builder builder = new Notification.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_now_playing)
            .addAction(action)
            .setContentTitle("Mouseworld Radio")
            .setContentText(metaData)
            .setContentIntent(pi)
            .setOngoing(true)
            .setStyle(style);

            lNotificationManager = (NotificationManager)     getSystemService(Context.NOTIFICATION_SERVICE);
            lNotificationManager.notify(NOTIFICATION_ID, builder.build());


//build the notification with stop action---this is called in a different block
buildNotification(generateAction(R.drawable.ic_av_stop, "Stop", ACTION_STOP));
4

0 回答 0