media3 mediaSessionService 从通知中删除搜索栏

问题描述 投票:0回答:1

我使用 MediaSessionService 在后台播放流音频。 通知显示,但它有一个我想删除的搜索栏。

在 MediaStyle 通知中禁用或隐藏搜索栏 这篇文章说要添加

putLong(MediaMetadata.METADATA_KEY_DURATION, -1L)
我不能这样做,因为 Media3 MediaMetadata 上没有“putLong”

    val builder = MediaMetadata.Builder().apply {
                setStation (args.name)
                setDisplayTitle(args.name)
                setSubtitle(getString(R.string.radio_notification_description, args.name))
                setArtworkUri(args.logoUrl?.toUri())
                setIsBrowsable(false)
            }

            val media = MediaItem.Builder().setMediaId(url).setMediaMetadata(builder.build()).build()
            controller.setMediaItem(media)
            controller.prepare()
            controller.play()

我也创建了这个,但我不确定如何从这里实际删除它。

@UnstableApi
class CustomMediaNotificationProvider(private val context: Context) : MediaNotification.Provider {

    override fun createNotification(
        mediaSession: MediaSession,
        customLayout: ImmutableList<CommandButton>,
        actionFactory: MediaNotification.ActionFactory,
        onNotificationChangedCallback: MediaNotification.Provider.Callback
    ): MediaNotification {

//        val notification = NotificationCompat.Builder(context, defaultMediaNotification.notification).build()
//        return  MediaNotification(defaultMediaNotification.notificationId,notification)

        val defaultMediaNotificationProvider = DefaultMediaNotificationProvider.Builder(context)
        return defaultMediaNotificationProvider.build().createNotification(mediaSession, customLayout, actionFactory, onNotificationChangedCallback)
    }

    override fun handleCustomCommand(
        session: MediaSession,
        action: String,
        extras: Bundle
    ): Boolean {
        return true
    }
}

或这里:

@RequiresApi(Build.VERSION_CODES.O)
    override fun onUpdateNotification(session: MediaSession, startInForegroundRequired: Boolean) {
        super.onUpdateNotification(session, startInForegroundRequired)
android exoplayer android-media3
1个回答
0
投票

您可以使用 ForwardingPlayer 作为底层播放器并按如下方式重写 getDuration 以禁用媒体样式通知中的搜索栏。

object: ForwardingPlayer(exoPlayer) {
    override fun getDuration(): Long {
        return C.TIME_UNSET
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.