gpt4 book ai didi

java - Exo播放器 : setNotificationListener is deprecated

转载 作者:行者123 更新时间:2023-12-01 19:19:15 27 4
gpt4 key购买 nike

Exoplayer 的最新更新 com.google.android.exoplayer:exoplayer:2.10.1 我注意到 setNotificationListener 方法现已弃用,文档称:

@param notificationListener The {@link NotificationListener}. @deprecated Pass the notification listener to the constructor instead.

我不明白,我应该在上面放置监听器的构造函数在哪里

 void exoPlayerNotification(Context context, SimpleExoPlayer exoPlayer, String title) {
String titlesonge;
String artist;
try {
titlesonge = StringUtils.substringBefore(title, " - ");
artist = StringUtils.substringAfter(title, " - ");
} catch (Exception e) {
titlesonge = title.substring(0, title.indexOf(" - "));
artist = title.substring(title.lastIndexOf(" - ") - 1);
}
String finalArtist = artist;
String finalTitlesonge = titlesonge;
PlayerNotificationManager mPlayerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
context,
"PRIMARY_CHANNEL_ID",
R.string.plaza,
NOTIFICATION_ID,
new PlayerNotificationManager.MediaDescriptionAdapter() {
@Override
public String getCurrentContentTitle(Player player) {
return finalArtist;
}

@Nullable
@Override
public PendingIntent createCurrentContentIntent(Player player) {
Intent intent = new Intent(service, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(service, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}

@Override
public String getCurrentContentText(Player player) {
return finalTitlesonge;
}

@Nullable
@Override
public Bitmap getCurrentLargeIcon(Player player, PlayerNotificationManager.BitmapCallback callback) {
return BitmapFactory.decodeResource(service.getResources(), R.drawable.largeicon);
}

@Nullable
@Override
public String getCurrentSubText(Player player) {
return null;
}
}
);
mPlayerNotificationManager.setUseNavigationActions(false);
mPlayerNotificationManager.setFastForwardIncrementMs(0);
mPlayerNotificationManager.setRewindIncrementMs(0);
mPlayerNotificationManager.setColorized(true);
mPlayerNotificationManager.setColor(0xFFBDBDBD);
mPlayerNotificationManager.setUseChronometer(true);
mPlayerNotificationManager.setPriority(NotificationCompat.PRIORITY_MAX);
mPlayerNotificationManager.setUsePlayPauseActions(true);
mPlayerNotificationManager.setUseStopAction(true);
mPlayerNotificationManager.setSmallIcon(R.drawable.smallwidth);
mPlayerNotificationManager.setNotificationListener(new PlayerNotificationManager.NotificationListener() {
@Override
public void onNotificationStarted(int notificationId, Notification notification) {
service.startForeground(notificationId, notification);
mPlayerNotificationManager.setColorized(true);
}

@Override
public void onNotificationCancelled(int notificationId) {
service.stopSelf();
cancelNotify();
}

@Override
public void onNotificationCancelled(int notificationId, boolean dismissedByUser) {
if (dismissedByUser)
exoPlayer.setPlayWhenReady(false);
}

@Override
public void onNotificationPosted(int notificationId, Notification notification, boolean ongoing) {

}
});
mPlayerNotificationManager.setPlayer(exoPlayer);
}

最佳答案

我也花了很长时间才发现这一点..

不要在创建 PlayerNotificationManager 后调用 .setNotificationListener(),而是在 mPlayerNotificationManager 构造函数中使用 NotificationListener 对象(作为第 6 个参数),如下所示:

    PlayerNotificationManager mPlayerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
context,
"PRIMARY_CHANNEL_ID",
R.string.plaza,
NOTIFICATION_ID,
new PlayerNotificationManager.MediaDescriptionAdapter() {...},
new PlayerNotificationManager.NotificationListener() {
// Implement your methods here again
}
);

关于java - Exo播放器 : setNotificationListener is deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56499756/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com