Skip to content

Commit 047fe21

Browse files
committed
Fix hiding player controls when playing from media button
DefaultControlDispatcher was removed in ExoPlayer 2.16.0, so the class extending it that handled play/pause was removed in #8020. The new solution is to use an instance of ForwardingPlayer. Call sessionConnector.setPlayer with an instance of ForwardingPlayer that overrides play() and pause() and calls the callback methods.
1 parent b59a601 commit 047fe21

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import androidx.annotation.Nullable;
1414
import androidx.media.session.MediaButtonReceiver;
1515

16+
import com.google.android.exoplayer2.ForwardingPlayer;
1617
import com.google.android.exoplayer2.Player;
1718
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
1819

@@ -55,7 +56,17 @@ public MediaSessionManager(@NonNull final Context context,
5556

5657
sessionConnector = new MediaSessionConnector(mediaSession);
5758
sessionConnector.setQueueNavigator(new PlayQueueNavigator(mediaSession, callback));
58-
sessionConnector.setPlayer(player);
59+
sessionConnector.setPlayer(new ForwardingPlayer(player) {
60+
@Override
61+
public void play() {
62+
callback.play();
63+
}
64+
65+
@Override
66+
public void pause() {
67+
callback.pause();
68+
}
69+
});
5970
}
6071

6172
@Nullable

0 commit comments

Comments
 (0)