Java Exoplayer玩家通知管理器onSwipe
我使用的是Exoplayer版本2.11.0,我想知道当用户向右滑动PlayerNotificationManager(类似于Spotify)时,是否有可能停止PlayerNotificationManager。默认情况下,我只能调用useStopAction(true) 这让我不满意 基于此,我们可以在exoplayer未播放时发出通知,取消onSwipeJava Exoplayer玩家通知管理器onSwipe,java,android,exoplayer2.x,Java,Android,Exoplayer2.x,我使用的是Exoplayer版本2.11.0,我想知道当用户向右滑动PlayerNotificationManager(类似于Spotify)时,是否有可能停止PlayerNotificationManager。默认情况下,我只能调用useStopAction(true) 这让我不满意 基于此,我们可以在exoplayer未播放时发出通知,取消onSwipe @Override public void onNotificationPosted(int notificationId, No
@Override
public void onNotificationPosted(int notificationId, Notification notification, boolean ongoing) {
if (ongoing) {
// Here Audio is playing, so we need to make sure the service will not get destroyed by calling startForeground.
startForeground(notificationId, notification);
} else {
//Here audio has stopped playing, so we can make notification dismissible on swipe.
stopForeground(false);
}
}
每次exoplayer更新通知后,都会调用onNotificationPosted。当播放机播放任何音频时,都是这样。因此,我们可以决定是否应该驳回通知
/** Returns whether the generated notification should be ongoing. */
protected boolean getOngoing(Player player) {
int playbackState = player.getPlaybackState();
return (playbackState == Player.STATE_BUFFERING || playbackState == Player.STATE_READY) && player.getPlayWhenReady();
}
欢迎来到stackoverflow。如果添加一些解释,说明代码的工作原理以及应该在哪里使用,您的答案会有很大的改进。
/** Returns whether the generated notification should be ongoing. */
protected boolean getOngoing(Player player) {
int playbackState = player.getPlaybackState();
return (playbackState == Player.STATE_BUFFERING || playbackState == Player.STATE_READY) && player.getPlayWhenReady();
}