mute-button implementation in main player

This commit is contained in:
karol 2020-02-23 22:32:23 +01:00
parent dc6a0e3eec
commit 4415888324
2 changed files with 36 additions and 0 deletions

View file

@ -532,6 +532,20 @@ public abstract class BasePlayer implements
if (simpleExoPlayer == null) return; if (simpleExoPlayer == null) return;
simpleExoPlayer.setShuffleModeEnabled(!simpleExoPlayer.getShuffleModeEnabled()); 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 // Progress Updates

View file

@ -40,6 +40,7 @@ import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -446,6 +447,7 @@ public final class MainVideoPlayer extends AppCompatActivity
private ImageButton toggleOrientationButton; private ImageButton toggleOrientationButton;
private ImageButton switchPopupButton; private ImageButton switchPopupButton;
private ImageButton switchBackgroundButton; private ImageButton switchBackgroundButton;
private ImageButton muteButton;
private RelativeLayout windowRootLayout; private RelativeLayout windowRootLayout;
private View secondaryControls; private View secondaryControls;
@ -482,6 +484,7 @@ public final class MainVideoPlayer extends AppCompatActivity
this.shareButton = rootView.findViewById(R.id.share); this.shareButton = rootView.findViewById(R.id.share);
this.toggleOrientationButton = rootView.findViewById(R.id.toggleOrientation); this.toggleOrientationButton = rootView.findViewById(R.id.toggleOrientation);
this.switchBackgroundButton = rootView.findViewById(R.id.switchBackground); this.switchBackgroundButton = rootView.findViewById(R.id.switchBackground);
this.muteButton = rootView.findViewById(R.id.switchMute);
this.switchPopupButton = rootView.findViewById(R.id.switchPopup); this.switchPopupButton = rootView.findViewById(R.id.switchPopup);
this.queueLayout = findViewById(R.id.playQueuePanel); this.queueLayout = findViewById(R.id.playQueuePanel);
@ -533,6 +536,7 @@ public final class MainVideoPlayer extends AppCompatActivity
shareButton.setOnClickListener(this); shareButton.setOnClickListener(this);
toggleOrientationButton.setOnClickListener(this); toggleOrientationButton.setOnClickListener(this);
switchBackgroundButton.setOnClickListener(this); switchBackgroundButton.setOnClickListener(this);
muteButton.setOnClickListener(this);
switchPopupButton.setOnClickListener(this); switchPopupButton.setOnClickListener(this);
getRootView().addOnLayoutChangeListener((view, l, t, r, b, ol, ot, or, ob) -> { getRootView().addOnLayoutChangeListener((view, l, t, r, b, ol, ot, or, ob) -> {
@ -670,6 +674,21 @@ public final class MainVideoPlayer extends AppCompatActivity
destroy(); destroy();
finish(); 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 @Override
@ -708,6 +727,9 @@ public final class MainVideoPlayer extends AppCompatActivity
} else if (v.getId() == switchBackgroundButton.getId()) { } else if (v.getId() == switchBackgroundButton.getId()) {
onPlayBackgroundButtonClicked(); onPlayBackgroundButtonClicked();
} else if (v.getId() == muteButton.getId()) {
onMuteUnmuteButtonClicled();
} else if (v.getId() == closeButton.getId()) { } else if (v.getId() == closeButton.getId()) {
onPlaybackShutdown(); onPlaybackShutdown();
return; return;