Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Exoplayer玩家通知管理器onSwipe_Java_Android_Exoplayer2.x - Fatal编程技术网

Java Exoplayer玩家通知管理器onSwipe

Java 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

我使用的是Exoplayer版本2.11.0,我想知道当用户向右滑动PlayerNotificationManager(类似于Spotify)时,是否有可能停止PlayerNotificationManager。默认情况下,我只能调用useStopAction(true) 这让我不满意

基于此,我们可以在exoplayer未播放时发出通知,取消onSwipe

  @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();
  }