From dc6a0e3eec32d21eddd10fe4bdd4147140d7f79a Mon Sep 17 00:00:00 2001 From: karol Date: Sun, 23 Feb 2020 21:28:40 +0100 Subject: [PATCH 01/15] mute-button added to activity_main_player.xml's --- .../activity_main_player.xml | 18 ++++++++++++++++++ .../main/res/layout/activity_main_player.xml | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/app/src/main/res/layout-large-land/activity_main_player.xml b/app/src/main/res/layout-large-land/activity_main_player.xml index 8e11b99f3..10fda556a 100644 --- a/app/src/main/res/layout-large-land/activity_main_player.xml +++ b/app/src/main/res/layout-large-land/activity_main_player.xml @@ -389,6 +389,24 @@ android:background="?attr/selectableItemBackground" android:contentDescription="@string/switch_to_background" tools:ignore="RtlHardcoded"/> + + + + + Date: Sun, 23 Feb 2020 22:32:23 +0100 Subject: [PATCH 02/15] mute-button implementation in main player --- .../org/schabi/newpipe/player/BasePlayer.java | 14 ++++++++++++ .../newpipe/player/MainVideoPlayer.java | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+) 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 46ca3921d..79496388c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -532,6 +532,20 @@ public abstract class BasePlayer implements if (simpleExoPlayer == null) return; simpleExoPlayer.setShuffleModeEnabled(!simpleExoPlayer.getShuffleModeEnabled()); } + /*////////////////////////////////////////////////////////////////////////// + // Mute / Unmute + //////////////////////////////////////////////////////////////////////////*/ + + public void onMuteUnmuteButtonClicled(){ + if (DEBUG) Log.d(TAG, "onMuteUnmuteButtonClicled() called"); + + if (simpleExoPlayer.getVolume() != 0) { + simpleExoPlayer.setVolume(0); + } + else { + simpleExoPlayer.setVolume(1); + } + } /*////////////////////////////////////////////////////////////////////////// // Progress Updates 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 3340f1107..18412b6cd 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -40,6 +40,7 @@ import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.content.res.AppCompatResources; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.ItemTouchHelper; import android.util.DisplayMetrics; @@ -446,6 +447,7 @@ public final class MainVideoPlayer extends AppCompatActivity private ImageButton toggleOrientationButton; private ImageButton switchPopupButton; private ImageButton switchBackgroundButton; + private ImageButton muteButton; private RelativeLayout windowRootLayout; private View secondaryControls; @@ -482,6 +484,7 @@ public final class MainVideoPlayer extends AppCompatActivity this.shareButton = rootView.findViewById(R.id.share); this.toggleOrientationButton = rootView.findViewById(R.id.toggleOrientation); this.switchBackgroundButton = rootView.findViewById(R.id.switchBackground); + this.muteButton = rootView.findViewById(R.id.switchMute); this.switchPopupButton = rootView.findViewById(R.id.switchPopup); this.queueLayout = findViewById(R.id.playQueuePanel); @@ -533,6 +536,7 @@ public final class MainVideoPlayer extends AppCompatActivity shareButton.setOnClickListener(this); toggleOrientationButton.setOnClickListener(this); switchBackgroundButton.setOnClickListener(this); + muteButton.setOnClickListener(this); switchPopupButton.setOnClickListener(this); getRootView().addOnLayoutChangeListener((view, l, t, r, b, ol, ot, or, ob) -> { @@ -670,6 +674,21 @@ public final class MainVideoPlayer extends AppCompatActivity destroy(); finish(); } + @Override + public void onMuteUnmuteButtonClicled() { + super.onMuteUnmuteButtonClicled(); + setMuteIcon(); + } + + public void setMuteIcon() { + if (simpleExoPlayer.getVolume() == 0){ + muteButton.setColorFilter(ContextCompat.getColor(context, R.color.white)); + } + + else { + muteButton.setColorFilter(ContextCompat.getColor(context, R.color.gray)); + } + } @Override @@ -708,6 +727,9 @@ public final class MainVideoPlayer extends AppCompatActivity } else if (v.getId() == switchBackgroundButton.getId()) { onPlayBackgroundButtonClicked(); + } else if (v.getId() == muteButton.getId()) { + onMuteUnmuteButtonClicled(); + } else if (v.getId() == closeButton.getId()) { onPlaybackShutdown(); return; From cc559dc9ce181fef19946667bfe4a9b5e827ee8d Mon Sep 17 00:00:00 2001 From: karol Date: Sun, 23 Feb 2020 22:55:34 +0100 Subject: [PATCH 03/15] isMuted() added --- .../java/org/schabi/newpipe/player/BasePlayer.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 79496388c..2fe04c9d1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -538,13 +538,11 @@ public abstract class BasePlayer implements public void onMuteUnmuteButtonClicled(){ if (DEBUG) Log.d(TAG, "onMuteUnmuteButtonClicled() called"); + simpleExoPlayer.setVolume(isMuted() ? 1 : 0); + } - if (simpleExoPlayer.getVolume() != 0) { - simpleExoPlayer.setVolume(0); - } - else { - simpleExoPlayer.setVolume(1); - } + public boolean isMuted(){ + return simpleExoPlayer.getVolume() == 0; } /*////////////////////////////////////////////////////////////////////////// From 2a63f2a3a633b18d87f4874f11d6961ad2e5a907 Mon Sep 17 00:00:00 2001 From: karol Date: Sun, 23 Feb 2020 23:31:30 +0100 Subject: [PATCH 04/15] mute-buton in queue layout and logic, but no icon change --- .../newpipe/player/ServicePlayerActivity.java | 8 +++++- .../activity_player_queue_control.xml | 27 ++++++++++++++----- .../layout/activity_player_queue_control.xml | 18 ++++++++++++- 3 files changed, 44 insertions(+), 9 deletions(-) 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 7aa2be05d..034746a2b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -83,6 +83,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity private TextView seekDisplay; private ImageButton repeatButton; + private ImageButton muteButton; private ImageButton backwardButton; private ImageButton playPauseButton; private ImageButton forwardButton; @@ -305,6 +306,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity private void buildControls() { repeatButton = rootView.findViewById(R.id.control_repeat); + muteButton = rootView.findViewById(R.id.control_mute); backwardButton = rootView.findViewById(R.id.control_backward); playPauseButton = rootView.findViewById(R.id.control_play_pause); forwardButton = rootView.findViewById(R.id.control_forward); @@ -314,6 +316,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity progressBar = rootView.findViewById(R.id.control_progress_bar); repeatButton.setOnClickListener(this); + muteButton.setOnClickListener(this); backwardButton.setOnClickListener(this); playPauseButton.setOnClickListener(this); forwardButton.setOnClickListener(this); @@ -446,6 +449,9 @@ public abstract class ServicePlayerActivity extends AppCompatActivity if (view.getId() == repeatButton.getId()) { player.onRepeatClicked(); + } else if (view.getId() == muteButton.getId()) { + player.onMuteUnmuteButtonClicled(); + } else if (view.getId() == backwardButton.getId()) { player.onPlayPrevious(); @@ -661,7 +667,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity final int shuffleAlpha = shuffled ? 255 : 77; shuffleButton.setImageAlpha(shuffleAlpha); } - + private void onPlaybackParameterChanged(final PlaybackParameters parameters) { if (parameters != null) { playbackSpeedButton.setText(formatSpeed(parameters.speed)); diff --git a/app/src/main/res/layout-land/activity_player_queue_control.xml b/app/src/main/res/layout-land/activity_player_queue_control.xml index 6468c6784..0277c28b5 100644 --- a/app/src/main/res/layout-land/activity_player_queue_control.xml +++ b/app/src/main/res/layout-land/activity_player_queue_control.xml @@ -192,7 +192,7 @@ android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_centerVertical="true" - android:layout_toLeftOf="@+id/control_repeat" + android:layout_toLeftOf="@+id/control_mute" android:gravity="center" android:minWidth="50dp" android:text="1x" @@ -201,13 +201,30 @@ android:background="?attr/selectableItemBackground" tools:ignore="HardcodedText,RtlHardcoded"/> + + - + + Date: Sun, 23 Feb 2020 23:44:16 +0100 Subject: [PATCH 05/15] icon change implemented in queque --- .../schabi/newpipe/player/BackgroundPlayer.java | 6 ++++++ .../schabi/newpipe/player/PopupVideoPlayer.java | 6 ++++++ .../newpipe/player/ServicePlayerActivity.java | 14 +++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) 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 9e23d9145..25a9f3be3 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -398,6 +398,12 @@ public final class BackgroundPlayer extends Service { updatePlayback(); } + @Override + public void onMuteUnmuteButtonClicled() { + super.onMuteUnmuteButtonClicled(); + updatePlayback(); + } + @Override public void onUpdateProgress(int currentProgress, int duration, int bufferPercent) { updateProgress(currentProgress, duration, bufferPercent); 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 fc14e8d51..88d227936 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -607,6 +607,12 @@ public final class PopupVideoPlayer extends Service { updatePlayback(); } + @Override + public void onMuteUnmuteButtonClicled() { + super.onMuteUnmuteButtonClicled(); + updatePlayback(); + } + @Override public void onUpdateProgress(int currentProgress, int duration, int bufferPercent) { updateProgress(currentProgress, duration, bufferPercent); 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 034746a2b..a3d8dde8d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -7,6 +7,7 @@ import android.os.Bundle; import android.os.IBinder; import android.provider.Settings; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.appcompat.widget.Toolbar; @@ -22,6 +23,7 @@ import android.widget.PopupMenu; import android.widget.ProgressBar; import android.widget.SeekBar; import android.widget.TextView; +import android.widget.Toast; import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; @@ -560,6 +562,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity onPlayModeChanged(repeatMode, shuffled); onPlaybackParameterChanged(parameters); onMaybePlaybackAdapterChanged(); + onMaybeMuteChanged(); } @Override @@ -667,7 +670,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity final int shuffleAlpha = shuffled ? 255 : 77; shuffleButton.setImageAlpha(shuffleAlpha); } - + private void onPlaybackParameterChanged(final PlaybackParameters parameters) { if (parameters != null) { playbackSpeedButton.setText(formatSpeed(parameters.speed)); @@ -682,4 +685,13 @@ public abstract class ServicePlayerActivity extends AppCompatActivity itemsList.setAdapter(maybeNewAdapter); } } + + private void onMaybeMuteChanged(){ + if (player.isMuted()) { + muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.white)); + } + else { + muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.gray)); + } + } } From 40f54aea5353cdcfc52a533665a5d495364c3a91 Mon Sep 17 00:00:00 2001 From: karol Date: Thu, 27 Feb 2020 22:30:18 +0100 Subject: [PATCH 06/15] 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) { From 0400fcb10609950c4b79b97ac104e0388c2aae8c Mon Sep 17 00:00:00 2001 From: karol Date: Thu, 27 Feb 2020 23:30:17 +0100 Subject: [PATCH 07/15] mute icon in main refactored --- .../newpipe/player/MainVideoPlayer.java | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) 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 0f7a7dcf9..d7b518771 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -34,6 +34,7 @@ import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; import android.provider.Settings; + import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -43,6 +44,7 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.ItemTouchHelper; + import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; @@ -115,7 +117,8 @@ public final class MainVideoPlayer extends AppCompatActivity private SharedPreferences defaultPreferences; - @Nullable private PlayerState playerState; + @Nullable + private PlayerState playerState; private boolean isInMultiWindow; private boolean isBackPressed; @@ -129,11 +132,13 @@ public final class MainVideoPlayer extends AppCompatActivity protected void onCreate(@Nullable Bundle savedInstanceState) { assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); - if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]"); + if (DEBUG) + Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]"); defaultPreferences = PreferenceManager.getDefaultSharedPreferences(this); ThemeHelper.setTheme(this); getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.BLACK); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + getWindow().setStatusBarColor(Color.BLACK); setVolumeControlStream(AudioManager.STREAM_MUSIC); WindowManager.LayoutParams lp = getWindow().getAttributes(); @@ -142,7 +147,7 @@ public final class MainVideoPlayer extends AppCompatActivity hideSystemUi(); setContentView(R.layout.activity_main_player); - playerImpl = new VideoPlayerImpl(this); + playerImpl = new VideoPlayerImpl(this); playerImpl.setup(findViewById(android.R.id.content)); if (savedInstanceState != null && savedInstanceState.get(KEY_SAVED_STATE) != null) { @@ -247,7 +252,7 @@ public final class MainVideoPlayer extends AppCompatActivity if (playerImpl == null) return; playerImpl.setRecovery(); - if(!playerImpl.gotDestroyed()) { + if (!playerImpl.gotDestroyed()) { playerState = createPlayerState(); } StateSaver.tryToSave(isChangingConfigurations(), null, outState, this); @@ -395,6 +400,16 @@ public final class MainVideoPlayer extends AppCompatActivity shuffleButton.setImageAlpha(shuffleAlpha); } + protected void setMuteButton(final ImageButton muteButton, final boolean isMuted) { + if (isMuted) { + muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.white)); + } else { + muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.gray)); + + } + } + + private boolean isInMultiWindow() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInMultiWindowMode(); } @@ -494,7 +509,7 @@ public final class MainVideoPlayer extends AppCompatActivity titleTextView.setSelected(true); channelTextView.setSelected(true); boolean showKodiButton = PreferenceManager.getDefaultSharedPreferences(this.context).getBoolean( - this.context.getString(R.string.show_play_with_kodi_key), false); + this.context.getString(R.string.show_play_with_kodi_key), false); kodiButton.setVisibility(showKodiButton ? View.VISIBLE : View.GONE); getRootView().setKeepScreenOn(true); @@ -676,20 +691,11 @@ public final class MainVideoPlayer extends AppCompatActivity destroy(); finish(); } + @Override public void onMuteUnmuteButtonClicled() { super.onMuteUnmuteButtonClicled(); - setMuteIcon(); - } - - public void setMuteIcon() { - if (simpleExoPlayer.getVolume() == 0){ - muteButton.setColorFilter(ContextCompat.getColor(context, R.color.white)); - } - - else { - muteButton.setColorFilter(ContextCompat.getColor(context, R.color.gray)); - } + updatePlaybackButtons(); } @@ -736,7 +742,7 @@ public final class MainVideoPlayer extends AppCompatActivity onPlaybackShutdown(); return; } else if (v.getId() == kodiButton.getId()) { - onKodiShare(); + onKodiShare(); } if (getCurrentState() != STATE_COMPLETED) { @@ -785,7 +791,7 @@ public final class MainVideoPlayer extends AppCompatActivity // share video at the current time (youtube.com/watch?v=ID&t=SECONDS) ShareUtils.shareUrl(MainVideoPlayer.this, playerImpl.getVideoTitle(), - playerImpl.getVideoUrl() + "&t=" + String.valueOf(playerImpl.getPlaybackSeekBar().getProgress()/1000)); + playerImpl.getVideoUrl() + "&t=" + String.valueOf(playerImpl.getPlaybackSeekBar().getProgress() / 1000)); } private void onScreenRotationClicked() { @@ -978,6 +984,7 @@ public final class MainVideoPlayer extends AppCompatActivity setRepeatModeButton(repeatButton, getRepeatMode()); setShuffleButton(shuffleButton, playQueue.isShuffled()); + setMuteButton(muteButton, playerImpl.isMuted()); } private void buildQueue() { @@ -1018,7 +1025,7 @@ public final class MainVideoPlayer extends AppCompatActivity @Override public void onSwiped(int index) { - if(index != -1) playQueue.remove(index); + if (index != -1) playQueue.remove(index); } }; } @@ -1097,7 +1104,8 @@ public final class MainVideoPlayer extends AppCompatActivity @Override public boolean onDoubleTap(MotionEvent e) { - if (DEBUG) Log.d(TAG, "onDoubleTap() called with: e = [" + e + "]" + "rawXy = " + e.getRawX() + ", " + e.getRawY() + ", xy = " + e.getX() + ", " + e.getY()); + if (DEBUG) + Log.d(TAG, "onDoubleTap() called with: e = [" + e + "]" + "rawXy = " + e.getRawX() + ", " + e.getRawY() + ", xy = " + e.getX() + ", " + e.getY()); if (e.getX() > playerImpl.getRootView().getWidth() * 2 / 3) { playerImpl.onFastForward(); @@ -1193,7 +1201,8 @@ public final class MainVideoPlayer extends AppCompatActivity layoutParams.screenBrightness = currentProgressPercent; getWindow().setAttributes(layoutParams); - if (DEBUG) Log.d(TAG, "onScroll().brightnessControl, currentBrightness = " + currentProgressPercent); + if (DEBUG) + Log.d(TAG, "onScroll().brightnessControl, currentBrightness = " + currentProgressPercent); final int resId = currentProgressPercent < 0.25 ? R.drawable.ic_brightness_low_white_72dp @@ -1232,7 +1241,8 @@ public final class MainVideoPlayer extends AppCompatActivity @Override public boolean onTouch(View v, MotionEvent event) { //noinspection PointlessBooleanExpression - if (DEBUG && false) Log.d(TAG, "onTouch() called with: v = [" + v + "], event = [" + event + "]"); + if (DEBUG && false) + Log.d(TAG, "onTouch() called with: v = [" + v + "], event = [" + event + "]"); gestureDetector.onTouchEvent(event); if (event.getAction() == MotionEvent.ACTION_UP && isMoving) { isMoving = false; From ee75909c80d399d03d548127ecc2454740ae5b51 Mon Sep 17 00:00:00 2001 From: karol Date: Sun, 1 Mar 2020 13:02:20 +0100 Subject: [PATCH 08/15] set mute button in main player from other player --- .../java/org/schabi/newpipe/player/MainVideoPlayer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 d7b518771..cad165ab6 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -695,7 +695,7 @@ public final class MainVideoPlayer extends AppCompatActivity @Override public void onMuteUnmuteButtonClicled() { super.onMuteUnmuteButtonClicled(); - updatePlaybackButtons(); + setMuteButton(muteButton, playerImpl.isMuted()); } @@ -785,6 +785,7 @@ public final class MainVideoPlayer extends AppCompatActivity animateView(secondaryControls, SLIDE_AND_ALPHA, !isMoreControlsVisible, DEFAULT_CONTROLS_DURATION); showControls(DEFAULT_CONTROLS_DURATION); + setMuteButton(muteButton, playerImpl.isMuted()); } private void onShareClicked() { @@ -984,7 +985,6 @@ public final class MainVideoPlayer extends AppCompatActivity setRepeatModeButton(repeatButton, getRepeatMode()); setShuffleButton(shuffleButton, playQueue.isShuffled()); - setMuteButton(muteButton, playerImpl.isMuted()); } private void buildQueue() { @@ -1090,6 +1090,10 @@ public final class MainVideoPlayer extends AppCompatActivity return repeatButton; } + public ImageButton getMuteButton() { + return muteButton; + } + public ImageButton getPlayPauseButton() { return playPauseButton; } From a6fcb70d1275e8a1fbc3f712b9152233b1fe8bb1 Mon Sep 17 00:00:00 2001 From: karol Date: Sun, 1 Mar 2020 16:42:46 +0100 Subject: [PATCH 09/15] fix typo --- .../java/org/schabi/newpipe/player/BackgroundPlayer.java | 4 ++-- app/src/main/java/org/schabi/newpipe/player/BasePlayer.java | 2 +- .../java/org/schabi/newpipe/player/MainVideoPlayer.java | 6 +++--- .../java/org/schabi/newpipe/player/PopupVideoPlayer.java | 4 ++-- .../org/schabi/newpipe/player/ServicePlayerActivity.java | 3 +-- 5 files changed, 9 insertions(+), 10 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 b020f234b..dbf27ea7c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -397,8 +397,8 @@ public final class BackgroundPlayer extends Service { } @Override - public void onMuteUnmuteButtonClicled() { - super.onMuteUnmuteButtonClicled(); + public void onMuteUnmuteButtonClicked() { + super.onMuteUnmuteButtonClicked(); updatePlayback(); } 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 ce2f94e0d..adffefa6e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -542,7 +542,7 @@ public abstract class BasePlayer implements // Mute / Unmute //////////////////////////////////////////////////////////////////////////*/ - public void onMuteUnmuteButtonClicled() { + public void onMuteUnmuteButtonClicked() { if (DEBUG) Log.d(TAG, "onMuteUnmuteButtonClicled() called"); simpleExoPlayer.setVolume(isMuted() ? 1 : 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 cad165ab6..63d95e74f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -693,8 +693,8 @@ public final class MainVideoPlayer extends AppCompatActivity } @Override - public void onMuteUnmuteButtonClicled() { - super.onMuteUnmuteButtonClicled(); + public void onMuteUnmuteButtonClicked() { + super.onMuteUnmuteButtonClicked(); setMuteButton(muteButton, playerImpl.isMuted()); } @@ -736,7 +736,7 @@ public final class MainVideoPlayer extends AppCompatActivity onPlayBackgroundButtonClicked(); } else if (v.getId() == muteButton.getId()) { - onMuteUnmuteButtonClicled(); + onMuteUnmuteButtonClicked(); } else if (v.getId() == closeButton.getId()) { onPlaybackShutdown(); 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 ff35aecb9..b7638eda7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -609,8 +609,8 @@ public final class PopupVideoPlayer extends Service { } @Override - public void onMuteUnmuteButtonClicled() { - super.onMuteUnmuteButtonClicled(); + public void onMuteUnmuteButtonClicked() { + super.onMuteUnmuteButtonClicked(); updatePlayback(); } 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 bb5593f09..c0a8d2bfd 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -23,7 +23,6 @@ import android.widget.PopupMenu; import android.widget.ProgressBar; import android.widget.SeekBar; import android.widget.TextView; -import android.widget.Toast; import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; @@ -453,7 +452,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity player.onRepeatClicked(); } else if (view.getId() == muteButton.getId()) { - player.onMuteUnmuteButtonClicled(); + player.onMuteUnmuteButtonClicked(); } else if (view.getId() == backwardButton.getId()) { player.onPlayPrevious(); From 92ee51b8db64b4ba6d4dfb22a925af2b4a37dd02 Mon Sep 17 00:00:00 2001 From: karol Date: Mon, 2 Mar 2020 21:12:02 +0100 Subject: [PATCH 10/15] resolved issues --- .../java/org/schabi/newpipe/player/BackgroundPlayer.java | 1 + .../main/java/org/schabi/newpipe/player/BasePlayer.java | 2 +- .../java/org/schabi/newpipe/player/MainVideoPlayer.java | 7 +------ .../org/schabi/newpipe/player/ServicePlayerActivity.java | 7 +------ 4 files changed, 4 insertions(+), 13 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 dbf27ea7c..4eaa2a73b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -341,6 +341,7 @@ 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); 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 adffefa6e..a71671e7b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -332,7 +332,7 @@ public abstract class BasePlayer implements if (playQueueAdapter != null) playQueueAdapter.dispose(); playQueueAdapter = new PlayQueueAdapter(context, playQueue); - if (isMuted) simpleExoPlayer.setVolume(0); + simpleExoPlayer.setVolume(isMuted ? 0 : 1); } public void destroyPlayer() { 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 63d95e74f..d74a739cf 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -401,12 +401,7 @@ public final class MainVideoPlayer extends AppCompatActivity } protected void setMuteButton(final ImageButton muteButton, final boolean isMuted) { - if (isMuted) { - muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.white)); - } else { - muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.gray)); - - } + muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), isMuted ? R.color.white : R.color.gray)); } 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 c0a8d2bfd..10b202e4c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -687,11 +687,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity } private void onMaybeMuteChanged(){ - if (player.isMuted()) { - muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.white)); - } - else { - muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.gray)); - } + muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), player.isMuted() ? R.color.white : R.color.gray)); } } From c79f09c119f156cddc574850f79b97a1d9eb9fb0 Mon Sep 17 00:00:00 2001 From: karol Date: Mon, 2 Mar 2020 22:52:58 +0100 Subject: [PATCH 11/15] mute button in actionbar, no color change --- .../org/schabi/newpipe/player/ServicePlayerActivity.java | 3 +++ app/src/main/res/menu/menu_play_queue.xml | 7 +++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 11 insertions(+) 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 10b202e4c..9099c9927 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -164,6 +164,9 @@ public abstract class ServicePlayerActivity extends AppCompatActivity case R.id.action_append_playlist: appendAllToPlaylist(); return true; + case R.id.action_mute: + player.onMuteUnmuteButtonClicked(); + return true; case R.id.action_system_audio: startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS)); return true; diff --git a/app/src/main/res/menu/menu_play_queue.xml b/app/src/main/res/menu/menu_play_queue.xml index be6cea46c..fc3fd07a8 100644 --- a/app/src/main/res/menu/menu_play_queue.xml +++ b/app/src/main/res/menu/menu_play_queue.xml @@ -10,6 +10,13 @@ android:visible="true" app:showAsAction="ifRoom"/> + + Rename Name Add To Playlist + Mute Set as Playlist Thumbnail Bookmark Playlist Remove Bookmark From 840bb29c542c797123eede58c15b3482a7e47bb6 Mon Sep 17 00:00:00 2001 From: karol Date: Tue, 3 Mar 2020 00:01:19 +0100 Subject: [PATCH 12/15] icon color change in action bar --- .../newpipe/player/ServicePlayerActivity.java | 25 ++++++++++++++++--- .../res/drawable/ic_volume_off_gray_24dp.xml | 5 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/ic_volume_off_gray_24dp.xml 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 9099c9927..75107a7e4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -3,15 +3,19 @@ package org.schabi.newpipe.player; import android.content.ComponentName; import android.content.Intent; import android.content.ServiceConnection; +import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.IBinder; import android.provider.Settings; + import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.ItemTouchHelper; + import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -94,6 +98,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity private TextView playbackSpeedButton; private TextView playbackPitchButton; + private Menu menu; + //////////////////////////////////////////////////////////////////////////// // Abstracts //////////////////////////////////////////////////////////////////////////// @@ -147,8 +153,10 @@ public abstract class ServicePlayerActivity extends AppCompatActivity @Override public boolean onCreateOptionsMenu(Menu menu) { + this.menu = menu; getMenuInflater().inflate(R.menu.menu_play_queue, menu); getMenuInflater().inflate(getPlayerOptionMenuResource(), menu); + onMaybeMuteChanged(); return true; } @@ -174,8 +182,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity this.player.setRecovery(); getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); getApplicationContext().startActivity( - getSwitchIntent(MainVideoPlayer.class) - .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()) + getSwitchIntent(MainVideoPlayer.class) + .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()) ); return true; } @@ -218,7 +226,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity } private void unbind() { - if(serviceBound) { + if (serviceBound) { unbindService(serviceConnection); serviceBound = false; stopPlayerListener(); @@ -689,7 +697,16 @@ public abstract class ServicePlayerActivity extends AppCompatActivity } } - private void onMaybeMuteChanged(){ + private void onMaybeMuteChanged() { muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), player.isMuted() ? R.color.white : R.color.gray)); + + if (menu != null) { + MenuItem item = menu.findItem(R.id.action_mute); + TypedArray a = getTheme().obtainStyledAttributes(R.style.Theme_AppCompat, new int[]{R.attr.volume_off}); + int attributeResourceId = a.getResourceId(0, 0); + Drawable drawableMuted = getResources().getDrawable(attributeResourceId); + Drawable drawableUnmuted = getResources().getDrawable(R.drawable.ic_volume_off_gray_24dp); + item.setIcon(player.isMuted() ? drawableMuted : drawableUnmuted); + } } } diff --git a/app/src/main/res/drawable/ic_volume_off_gray_24dp.xml b/app/src/main/res/drawable/ic_volume_off_gray_24dp.xml new file mode 100644 index 000000000..156ee53bb --- /dev/null +++ b/app/src/main/res/drawable/ic_volume_off_gray_24dp.xml @@ -0,0 +1,5 @@ + + + From 1ae8a72ba6d222b6fbf8977f8932f4835dbe85cc Mon Sep 17 00:00:00 2001 From: karol Date: Wed, 4 Mar 2020 18:37:04 +0100 Subject: [PATCH 13/15] mute icon change in action bar --- .../newpipe/player/ServicePlayerActivity.java | 12 ++------- .../res/drawable/ic_volume_off_gray_24dp.xml | 13 ++++++--- .../activity_player_queue_control.xml | 27 +++++-------------- .../layout/activity_player_queue_control.xml | 18 +------------ 4 files changed, 19 insertions(+), 51 deletions(-) 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 75107a7e4..07cdd73da 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -88,7 +88,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity private TextView seekDisplay; private ImageButton repeatButton; - private ImageButton muteButton; private ImageButton backwardButton; private ImageButton playPauseButton; private ImageButton forwardButton; @@ -319,7 +318,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity private void buildControls() { repeatButton = rootView.findViewById(R.id.control_repeat); - muteButton = rootView.findViewById(R.id.control_mute); backwardButton = rootView.findViewById(R.id.control_backward); playPauseButton = rootView.findViewById(R.id.control_play_pause); forwardButton = rootView.findViewById(R.id.control_forward); @@ -329,7 +327,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity progressBar = rootView.findViewById(R.id.control_progress_bar); repeatButton.setOnClickListener(this); - muteButton.setOnClickListener(this); backwardButton.setOnClickListener(this); playPauseButton.setOnClickListener(this); forwardButton.setOnClickListener(this); @@ -462,10 +459,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity if (view.getId() == repeatButton.getId()) { player.onRepeatClicked(); - } else if (view.getId() == muteButton.getId()) { - player.onMuteUnmuteButtonClicked(); - - } else if (view.getId() == backwardButton.getId()) { + } else if (view.getId() == backwardButton.getId()) { player.onPlayPrevious(); } else if (view.getId() == playPauseButton.getId()) { @@ -698,9 +692,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity } private void onMaybeMuteChanged() { - muteButton.setColorFilter(ContextCompat.getColor(getApplicationContext(), player.isMuted() ? R.color.white : R.color.gray)); - - if (menu != null) { + if (menu != null && player != null) { MenuItem item = menu.findItem(R.id.action_mute); TypedArray a = getTheme().obtainStyledAttributes(R.style.Theme_AppCompat, new int[]{R.attr.volume_off}); int attributeResourceId = a.getResourceId(0, 0); diff --git a/app/src/main/res/drawable/ic_volume_off_gray_24dp.xml b/app/src/main/res/drawable/ic_volume_off_gray_24dp.xml index 156ee53bb..ade6bfec2 100644 --- a/app/src/main/res/drawable/ic_volume_off_gray_24dp.xml +++ b/app/src/main/res/drawable/ic_volume_off_gray_24dp.xml @@ -1,5 +1,10 @@ - - + + diff --git a/app/src/main/res/layout-land/activity_player_queue_control.xml b/app/src/main/res/layout-land/activity_player_queue_control.xml index 0277c28b5..6468c6784 100644 --- a/app/src/main/res/layout-land/activity_player_queue_control.xml +++ b/app/src/main/res/layout-land/activity_player_queue_control.xml @@ -192,7 +192,7 @@ android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_centerVertical="true" - android:layout_toLeftOf="@+id/control_mute" + android:layout_toLeftOf="@+id/control_repeat" android:gravity="center" android:minWidth="50dp" android:text="1x" @@ -201,30 +201,13 @@ android:background="?attr/selectableItemBackground" tools:ignore="HardcodedText,RtlHardcoded"/> - - + - - Date: Wed, 4 Mar 2020 18:53:17 +0100 Subject: [PATCH 14/15] mute/unmute text change in action bar --- .../org/schabi/newpipe/player/ServicePlayerActivity.java | 8 +++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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 07cdd73da..e7700351e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -459,7 +459,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity if (view.getId() == repeatButton.getId()) { player.onRepeatClicked(); - } else if (view.getId() == backwardButton.getId()) { + } else if (view.getId() == backwardButton.getId()) { player.onPlayPrevious(); } else if (view.getId() == playPauseButton.getId()) { @@ -694,6 +694,12 @@ public abstract class ServicePlayerActivity extends AppCompatActivity private void onMaybeMuteChanged() { if (menu != null && player != null) { MenuItem item = menu.findItem(R.id.action_mute); + + //Change the mute-button item in ActionBar + //1) Text change: + item.setTitle(player.isMuted() ? R.string.unmute : R.string.mute); + + //2) Icon change accordingly to current App Theme TypedArray a = getTheme().obtainStyledAttributes(R.style.Theme_AppCompat, new int[]{R.attr.volume_off}); int attributeResourceId = a.getResourceId(0, 0); Drawable drawableMuted = getResources().getDrawable(attributeResourceId); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2f0803e1a..773614263 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -449,6 +449,7 @@ Name Add To Playlist Mute + Unmute Set as Playlist Thumbnail Bookmark Playlist Remove Bookmark From 55d7be0b2fb9e08402e28a560cdc63fe787d3afb Mon Sep 17 00:00:00 2001 From: karol Date: Thu, 5 Mar 2020 19:07:46 +0100 Subject: [PATCH 15/15] null risk issue --- app/src/main/java/org/schabi/newpipe/player/BasePlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a71671e7b..08fdb9258 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -277,7 +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()); + final boolean isMuted = intent.getBooleanExtra(IS_MUTED, simpleExoPlayer == null ? false : isMuted()); // seek to timestamp if stream is already playing if (simpleExoPlayer != null