From 40f54aea5353cdcfc52a533665a5d495364c3a91 Mon Sep 17 00:00:00 2001 From: karol Date: Thu, 27 Feb 2020 22:30:18 +0100 Subject: [PATCH] mute intent send between main-bckgrnd-popup players --- .../newpipe/player/BackgroundPlayer.java | 12 +++++------- .../org/schabi/newpipe/player/BasePlayer.java | 18 ++++++++++++------ .../schabi/newpipe/player/MainVideoPlayer.java | 8 +++++--- .../newpipe/player/PopupVideoPlayer.java | 3 ++- .../newpipe/player/ServicePlayerActivity.java | 3 ++- .../schabi/newpipe/util/NavigationHelper.java | 6 ++++-- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 25a9f3be3..b020f234b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -30,16 +30,16 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.os.Build; import android.os.IBinder; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; -import androidx.core.app.NotificationCompat; - import android.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.widget.RemoteViews; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import androidx.core.app.NotificationCompat; + import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.source.MediaSource; @@ -341,7 +341,6 @@ public final class BackgroundPlayer extends Service { @Override public void handleIntent(final Intent intent) { super.handleIntent(intent); - resetNotification(); if (bigNotRemoteView != null) bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 0, false); @@ -389,7 +388,6 @@ public final class BackgroundPlayer extends Service { @Override public void onPrepared(boolean playWhenReady) { super.onPrepared(playWhenReady); - simpleExoPlayer.setVolume(1f); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 2fe04c9d1..ce2f94e0d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -153,6 +153,8 @@ public abstract class BasePlayer implements public static final String START_PAUSED = "start_paused"; @NonNull public static final String SELECT_ON_APPEND = "select_on_append"; + @NonNull + public static final String IS_MUTED = "is_muted"; /*////////////////////////////////////////////////////////////////////////// // Playback @@ -275,6 +277,7 @@ public abstract class BasePlayer implements final float playbackPitch = intent.getFloatExtra(PLAYBACK_PITCH, getPlaybackPitch()); final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE, getPlaybackSkipSilence()); + final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted()); // seek to timestamp if stream is already playing if (simpleExoPlayer != null @@ -283,7 +286,7 @@ public abstract class BasePlayer implements && playQueue.getItem() != null && queue.getItem().getUrl().equals(playQueue.getItem().getUrl()) && queue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET - ) { + ) { simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition()); return; @@ -293,7 +296,7 @@ public abstract class BasePlayer implements stateLoader = recordManager.loadStreamState(item) .observeOn(AndroidSchedulers.mainThread()) .doFinally(() -> initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, - /*playOnInit=*/true)) + /*playOnInit=*/true, isMuted)) .subscribe( state -> queue.setRecovery(queue.getIndex(), state.getProgressTime()), error -> { @@ -306,7 +309,7 @@ public abstract class BasePlayer implements } // Good to go... initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, - /*playOnInit=*/!intent.getBooleanExtra(START_PAUSED, false)); + /*playOnInit=*/!intent.getBooleanExtra(START_PAUSED, false), isMuted); } protected void initPlayback(@NonNull final PlayQueue queue, @@ -314,7 +317,8 @@ public abstract class BasePlayer implements final float playbackSpeed, final float playbackPitch, final boolean playbackSkipSilence, - final boolean playOnReady) { + final boolean playOnReady, + final boolean isMuted) { destroyPlayer(); initPlayer(playOnReady); setRepeatMode(repeatMode); @@ -327,6 +331,8 @@ public abstract class BasePlayer implements if (playQueueAdapter != null) playQueueAdapter.dispose(); playQueueAdapter = new PlayQueueAdapter(context, playQueue); + + if (isMuted) simpleExoPlayer.setVolume(0); } public void destroyPlayer() { @@ -536,12 +542,12 @@ public abstract class BasePlayer implements // Mute / Unmute //////////////////////////////////////////////////////////////////////////*/ - public void onMuteUnmuteButtonClicled(){ + public void onMuteUnmuteButtonClicled() { if (DEBUG) Log.d(TAG, "onMuteUnmuteButtonClicled() called"); simpleExoPlayer.setVolume(isMuted() ? 1 : 0); } - public boolean isMuted(){ + public boolean isMuted() { return simpleExoPlayer.getVolume() == 0; } diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 18412b6cd..0f7a7dcf9 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -219,7 +219,7 @@ public final class MainVideoPlayer extends AppCompatActivity playerImpl.setPlaybackQuality(playerState.getPlaybackQuality()); playerImpl.initPlayback(playerState.getPlayQueue(), playerState.getRepeatMode(), playerState.getPlaybackSpeed(), playerState.getPlaybackPitch(), - playerState.isPlaybackSkipSilence(), playerState.wasPlaying()); + playerState.isPlaybackSkipSilence(), playerState.wasPlaying(), playerImpl.isMuted()); } } @@ -642,7 +642,8 @@ public final class MainVideoPlayer extends AppCompatActivity this.getPlaybackSkipSilence(), this.getPlaybackQuality(), false, - !isPlaying() + !isPlaying(), + isMuted() ); context.startService(intent); @@ -666,7 +667,8 @@ public final class MainVideoPlayer extends AppCompatActivity this.getPlaybackSkipSilence(), this.getPlaybackQuality(), false, - !isPlaying() + !isPlaying(), + isMuted() ); context.startService(intent); diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 88d227936..ff35aecb9 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -571,7 +571,8 @@ public final class PopupVideoPlayer extends Service { this.getPlaybackSkipSilence(), this.getPlaybackQuality(), false, - !isPlaying() + !isPlaying(), + isMuted() ); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index a3d8dde8d..bb5593f09 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -197,7 +197,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity this.player.getPlaybackSkipSilence(), null, false, - false + false, + this.player.isMuted() ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()); } diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index a19aa92ae..98264e1bf 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -110,13 +110,15 @@ public class NavigationHelper { final boolean playbackSkipSilence, @Nullable final String playbackQuality, final boolean resumePlayback, - final boolean startPaused) { + final boolean startPaused, + final boolean isMuted) { return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback) .putExtra(BasePlayer.REPEAT_MODE, repeatMode) .putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed) .putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch) .putExtra(BasePlayer.PLAYBACK_SKIP_SILENCE, playbackSkipSilence) - .putExtra(BasePlayer.START_PAUSED, startPaused); + .putExtra(BasePlayer.START_PAUSED, startPaused) + .putExtra(BasePlayer.IS_MUTED, isMuted); } public static void playOnMainPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {