Skip to content

Commit

Permalink
Add back the mute/unmute control in VR video control
Browse files Browse the repository at this point in the history
The original code has the volume control, but since
volume control now is not supported in Gecko media session,
we add the canCtrlVolume() in WMediaSession and return false
in Gecko Session. We call it and check the availability
when the volume button is on hover.

Signed-off-by: Songlin Jiang <sjiang@igalia.com>
  • Loading branch information
HollowMan6 authored and svillar committed Sep 29, 2023
1 parent 2bb0933 commit 3afa755
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ public void muteAudio(boolean mute) {
return;
getMediaSession().setMute(mute);
}

@Override
public boolean canCtrlVolume() {
// TODO: Check if the media session in Chromium supports volume control.
return false;
}
}

private void updatePosition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,11 @@ public void skipAd() {
public void muteAudio(boolean mute) {
mGeckoMediaSession.muteAudio(mute);
}

@Override
public boolean canCtrlVolume() {
// Gecko MediaSession doesn't have a way to control volume.
return false;
}
}
}
5 changes: 5 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/browser/Media.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ public void setVolume(double aVolume) {
// TODO: mMediaSession doesn't seem to have a way to set volume. Should we change system volume instead?
}

public boolean canCtrlVolume() {
return mMediaSession != null && mMediaSession.canCtrlVolume();
}

public void setMuted(boolean aIsMuted) {
if (mMediaSession != null) {
mMediaSession.muteAudio(aIsMuted);
mIsMuted = aIsMuted;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public interface WMediaSession {
*/
void muteAudio(final boolean mute);

/**
* Check whether the media session supports volume control.
*
* @return True if this media session supports volume control, false otherwise.
*/
boolean canCtrlVolume();

/** Implement this delegate to receive media session events. */
@UiThread
interface Delegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ private void updateUI() {
mMedia.setMuted(true);
mBinding.volumeControl.setVolume(0);
}
mBinding.setMuted(mMedia.isMuted());
mBinding.mediaVolumeButton.requestFocusFromTouch();
});

Expand Down Expand Up @@ -223,6 +224,11 @@ public void onSeekBarActionCancelled() {
return false;
});
mBinding.mediaVolumeButton.setOnHoverListener((v, event) -> {
// Only show the volume control when it's supported
if (!mMedia.canCtrlVolume()) {
return false;
}

float startY = v.getY();
float maxY = startY + v.getHeight();
//for this we only hide on the left side of volume button or outside y area of button
Expand Down Expand Up @@ -315,7 +321,6 @@ public void setMedia(Media aMedia) {
mBinding.mediaControlSeekBar.setCurrentTime(mMedia.getCurrentTime());
mBinding.setPlaying(mMedia.isPlaying());
mBinding.mediaControlSeekBar.setSeekable(mMedia.canSeek());
mBinding.mediaVolumeButton.setEnabled(false);

mMedia.addMediaListener(this);
}
Expand Down

0 comments on commit 3afa755

Please sign in to comment.