1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-26 01:50:32 +00:00

mute intent send between main-bckgrnd-popup players

This commit is contained in:
karol 2020-02-27 22:30:18 +01:00
parent c4d5886059
commit 40f54aea53
6 changed files with 30 additions and 20 deletions

View File

@ -30,16 +30,16 @@ import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Build; import android.os.Build;
import android.os.IBinder; 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.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.RemoteViews; 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.PlaybackParameters;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
@ -341,7 +341,6 @@ public final class BackgroundPlayer extends Service {
@Override @Override
public void handleIntent(final Intent intent) { public void handleIntent(final Intent intent) {
super.handleIntent(intent); super.handleIntent(intent);
resetNotification(); resetNotification();
if (bigNotRemoteView != null) if (bigNotRemoteView != null)
bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 0, false); bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 0, false);
@ -389,7 +388,6 @@ public final class BackgroundPlayer extends Service {
@Override @Override
public void onPrepared(boolean playWhenReady) { public void onPrepared(boolean playWhenReady) {
super.onPrepared(playWhenReady); super.onPrepared(playWhenReady);
simpleExoPlayer.setVolume(1f);
} }
@Override @Override

View File

@ -153,6 +153,8 @@ public abstract class BasePlayer implements
public static final String START_PAUSED = "start_paused"; public static final String START_PAUSED = "start_paused";
@NonNull @NonNull
public static final String SELECT_ON_APPEND = "select_on_append"; public static final String SELECT_ON_APPEND = "select_on_append";
@NonNull
public static final String IS_MUTED = "is_muted";
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Playback // Playback
@ -275,6 +277,7 @@ public abstract class BasePlayer implements
final float playbackPitch = intent.getFloatExtra(PLAYBACK_PITCH, getPlaybackPitch()); final float playbackPitch = intent.getFloatExtra(PLAYBACK_PITCH, getPlaybackPitch());
final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE, final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE,
getPlaybackSkipSilence()); getPlaybackSkipSilence());
final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted());
// seek to timestamp if stream is already playing // seek to timestamp if stream is already playing
if (simpleExoPlayer != null if (simpleExoPlayer != null
@ -293,7 +296,7 @@ public abstract class BasePlayer implements
stateLoader = recordManager.loadStreamState(item) stateLoader = recordManager.loadStreamState(item)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.doFinally(() -> initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, .doFinally(() -> initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true)) /*playOnInit=*/true, isMuted))
.subscribe( .subscribe(
state -> queue.setRecovery(queue.getIndex(), state.getProgressTime()), state -> queue.setRecovery(queue.getIndex(), state.getProgressTime()),
error -> { error -> {
@ -306,7 +309,7 @@ public abstract class BasePlayer implements
} }
// Good to go... // Good to go...
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, 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, protected void initPlayback(@NonNull final PlayQueue queue,
@ -314,7 +317,8 @@ public abstract class BasePlayer implements
final float playbackSpeed, final float playbackSpeed,
final float playbackPitch, final float playbackPitch,
final boolean playbackSkipSilence, final boolean playbackSkipSilence,
final boolean playOnReady) { final boolean playOnReady,
final boolean isMuted) {
destroyPlayer(); destroyPlayer();
initPlayer(playOnReady); initPlayer(playOnReady);
setRepeatMode(repeatMode); setRepeatMode(repeatMode);
@ -327,6 +331,8 @@ public abstract class BasePlayer implements
if (playQueueAdapter != null) playQueueAdapter.dispose(); if (playQueueAdapter != null) playQueueAdapter.dispose();
playQueueAdapter = new PlayQueueAdapter(context, playQueue); playQueueAdapter = new PlayQueueAdapter(context, playQueue);
if (isMuted) simpleExoPlayer.setVolume(0);
} }
public void destroyPlayer() { public void destroyPlayer() {

View File

@ -219,7 +219,7 @@ public final class MainVideoPlayer extends AppCompatActivity
playerImpl.setPlaybackQuality(playerState.getPlaybackQuality()); playerImpl.setPlaybackQuality(playerState.getPlaybackQuality());
playerImpl.initPlayback(playerState.getPlayQueue(), playerState.getRepeatMode(), playerImpl.initPlayback(playerState.getPlayQueue(), playerState.getRepeatMode(),
playerState.getPlaybackSpeed(), playerState.getPlaybackPitch(), 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.getPlaybackSkipSilence(),
this.getPlaybackQuality(), this.getPlaybackQuality(),
false, false,
!isPlaying() !isPlaying(),
isMuted()
); );
context.startService(intent); context.startService(intent);
@ -666,7 +667,8 @@ public final class MainVideoPlayer extends AppCompatActivity
this.getPlaybackSkipSilence(), this.getPlaybackSkipSilence(),
this.getPlaybackQuality(), this.getPlaybackQuality(),
false, false,
!isPlaying() !isPlaying(),
isMuted()
); );
context.startService(intent); context.startService(intent);

View File

@ -571,7 +571,8 @@ public final class PopupVideoPlayer extends Service {
this.getPlaybackSkipSilence(), this.getPlaybackSkipSilence(),
this.getPlaybackQuality(), this.getPlaybackQuality(),
false, false,
!isPlaying() !isPlaying(),
isMuted()
); );
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);

View File

@ -197,7 +197,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
this.player.getPlaybackSkipSilence(), this.player.getPlaybackSkipSilence(),
null, null,
false, false,
false false,
this.player.isMuted()
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()); .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying());
} }

View File

@ -110,13 +110,15 @@ public class NavigationHelper {
final boolean playbackSkipSilence, final boolean playbackSkipSilence,
@Nullable final String playbackQuality, @Nullable final String playbackQuality,
final boolean resumePlayback, final boolean resumePlayback,
final boolean startPaused) { final boolean startPaused,
final boolean isMuted) {
return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback) return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback)
.putExtra(BasePlayer.REPEAT_MODE, repeatMode) .putExtra(BasePlayer.REPEAT_MODE, repeatMode)
.putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed) .putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed)
.putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch) .putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch)
.putExtra(BasePlayer.PLAYBACK_SKIP_SILENCE, playbackSkipSilence) .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) { public static void playOnMainPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {