簡體   English   中英

PlayerNotificationManager 沒有顯示在 exoplayer 上播放視頻的通知,android?

[英]PlayerNotificationManager not showing notification for playing video on exoplayer, android?

我的應用播放視頻

我正在關注這個Exoplayer 通知

有相同的代碼

 PlayerNotificationManager playerNotificationManager = new PlayerNotificationManager(
            appCMSPresenter.getCurrentContext(),
            "kingkdfn",
            459, new DescriptionAdapter());

    playerNotificationManager.setPlayer(getPlayer());

描述適配器

public class DescriptionAdapter implements
    PlayerNotificationManager.MediaDescriptionAdapter {

@Override
public String getCurrentContentTitle(Player player) {
    int window = player.getCurrentWindowIndex();
    return "getTitle(window)";
}

@Nullable
@Override
public String getCurrentContentText(Player player) {
    int window = player.getCurrentWindowIndex();
    return "getDescription(window)";
}

@Nullable
@Override
public Bitmap getCurrentLargeIcon(Player player,
                                  PlayerNotificationManager.BitmapCallback callback) {

    return null;
}

@Nullable
@Override
public PendingIntent createCurrentContentIntent(Player player) {
    return null;
}
}

全部添加到清單中

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

但是在播放視頻時仍然沒有顯示通知。 我需要添加任何額外的東西嗎?

創建通知

public void createNotification() {
        if (notificationAdapter == null)
            notificationAdapter = new PlayerNotificationAdapter();
        if (pnm == null) {
            pnm = new PlayerNotificationManager.Builder(mContext, 239, mContext.getString(R.string.player_notification_channel_id))
                    .setChannelNameResourceId(R.string.player_notification_channel_name)
                    .setChannelDescriptionResourceId(R.string.player_notification_channel_desc)
                    .setMediaDescriptionAdapter(notificationAdapter).build();
        }
}

通知適配器

class PlayerNotificationAdapter : PlayerNotificationManager.MediaDescriptionAdapter {

override fun getCurrentContentTitle(player: Player): String {
    return "Content Title"
}

override fun createCurrentContentIntent(player: Player): PendingIntent? {
    return null
}

override fun getCurrentContentText(player: Player): String? {
    return "Content Description"
}

override fun getCurrentLargeIcon(player: Player, callback: PlayerNotificationManager.BitmapCallback): Bitmap? {
    return playerImage()
}

fun playerImage(): Bitmap? {
    var image: Bitmap? = null
    try {
        var url = URL("content image url")
        image = BitmapFactory.decodeStream(url.openConnection().getInputStream())
    } catch (e: IOException) {

    }
    return image
}
}

將播放器設置為通知管理器

if (pnm != null) {
                    pnm.setUseNextAction(false);
                    pnm.setUsePreviousAction(false);
                    MediaSessionCompat mediaSession = new MediaSessionCompat(mContext, "Player");
                    mediaSession.setActive(true);
                    mediaSession.setMetadata(new MediaMetadataCompat.Builder()
                            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
                            .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, description)
                            .build());
                    MediaSessionConnector mediaSessionConnector =
                            new MediaSessionConnector(mediaSession);
                    mediaSessionConnector.setPlayer(simpleExoPlayer);
                    pnm.setMediaSessionToken(mediaSession.getSessionToken());
                    pnm.setPlayer(simpleExoPlayer);
                    pnm.setPriority(PRIORITY_LOW);
                }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM