Merge branch 'media-session-fix' of https://github.com/karyogamy/NewPipe into test
This commit is contained in:
commit
8a1c283542
|
@ -271,6 +271,7 @@ public abstract class BasePlayer implements
|
||||||
if (audioReactor != null) audioReactor.dispose();
|
if (audioReactor != null) audioReactor.dispose();
|
||||||
if (playbackManager != null) playbackManager.dispose();
|
if (playbackManager != null) playbackManager.dispose();
|
||||||
if (databaseUpdateReactor != null) databaseUpdateReactor.dispose();
|
if (databaseUpdateReactor != null) databaseUpdateReactor.dispose();
|
||||||
|
if (mediaSessionManager != null) mediaSessionManager.dispose();
|
||||||
|
|
||||||
if (playQueueAdapter != null) {
|
if (playQueueAdapter != null) {
|
||||||
playQueueAdapter.unsetSelectedListener();
|
playQueueAdapter.unsetSelectedListener();
|
||||||
|
|
|
@ -11,7 +11,6 @@ import android.view.KeyEvent;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
||||||
|
|
||||||
import org.schabi.newpipe.player.mediasession.DummyPlaybackPreparer;
|
|
||||||
import org.schabi.newpipe.player.mediasession.MediaSessionCallback;
|
import org.schabi.newpipe.player.mediasession.MediaSessionCallback;
|
||||||
import org.schabi.newpipe.player.mediasession.PlayQueueNavigator;
|
import org.schabi.newpipe.player.mediasession.PlayQueueNavigator;
|
||||||
import org.schabi.newpipe.player.mediasession.PlayQueuePlaybackController;
|
import org.schabi.newpipe.player.mediasession.PlayQueuePlaybackController;
|
||||||
|
@ -26,10 +25,12 @@ public class MediaSessionManager {
|
||||||
@NonNull final Player player,
|
@NonNull final Player player,
|
||||||
@NonNull final MediaSessionCallback callback) {
|
@NonNull final MediaSessionCallback callback) {
|
||||||
this.mediaSession = new MediaSessionCompat(context, TAG);
|
this.mediaSession = new MediaSessionCompat(context, TAG);
|
||||||
|
this.mediaSession.setActive(true);
|
||||||
|
|
||||||
this.sessionConnector = new MediaSessionConnector(mediaSession,
|
this.sessionConnector = new MediaSessionConnector(mediaSession,
|
||||||
new PlayQueuePlaybackController(callback));
|
new PlayQueuePlaybackController(callback));
|
||||||
this.sessionConnector.setQueueNavigator(new PlayQueueNavigator(mediaSession, callback));
|
this.sessionConnector.setQueueNavigator(new PlayQueueNavigator(mediaSession, callback));
|
||||||
this.sessionConnector.setPlayer(player, new DummyPlaybackPreparer());
|
this.sessionConnector.setPlayer(player, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -37,4 +38,11 @@ public class MediaSessionManager {
|
||||||
public KeyEvent handleMediaButtonIntent(final Intent intent) {
|
public KeyEvent handleMediaButtonIntent(final Intent intent) {
|
||||||
return MediaButtonReceiver.handleIntent(mediaSession, intent);
|
return MediaButtonReceiver.handleIntent(mediaSession, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
this.sessionConnector.setPlayer(null, null);
|
||||||
|
this.sessionConnector.setQueueNavigator(null);
|
||||||
|
this.mediaSession.setActive(false);
|
||||||
|
this.mediaSession.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
package org.schabi.newpipe.player.mediasession;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.ResultReceiver;
|
|
||||||
|
|
||||||
import com.google.android.exoplayer2.Player;
|
|
||||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
|
||||||
|
|
||||||
public class DummyPlaybackPreparer implements MediaSessionConnector.PlaybackPreparer {
|
|
||||||
@Override
|
|
||||||
public long getSupportedPrepareActions() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepare() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareFromMediaId(String mediaId, Bundle extras) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareFromSearch(String query, Bundle extras) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareFromUri(Uri uri, Bundle extras) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getCommands() {
|
|
||||||
return new String[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(Player player, String command, Bundle extras, ResultReceiver cb) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,5 +13,4 @@ public interface MediaSessionCallback {
|
||||||
|
|
||||||
void onPlay();
|
void onPlay();
|
||||||
void onPause();
|
void onPause();
|
||||||
void onSetShuffle(final boolean isShuffled);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package org.schabi.newpipe.player.mediasession;
|
package org.schabi.newpipe.player.mediasession;
|
||||||
|
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
|
||||||
|
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.ext.mediasession.DefaultPlaybackController;
|
import com.google.android.exoplayer2.ext.mediasession.DefaultPlaybackController;
|
||||||
|
|
||||||
|
@ -22,10 +20,4 @@ public class PlayQueuePlaybackController extends DefaultPlaybackController {
|
||||||
public void onPause(Player player) {
|
public void onPause(Player player) {
|
||||||
callback.onPause();
|
callback.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSetShuffleMode(Player player, int shuffleMode) {
|
|
||||||
callback.onSetShuffle(shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_ALL
|
|
||||||
|| shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,9 +69,4 @@ public class BasePlayerMediaSession implements MediaSessionCallback {
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
player.onPause();
|
player.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSetShuffle(boolean isShuffled) {
|
|
||||||
player.onShuffleModeEnabledChanged(isShuffled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue