Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fix wrongly displayed "Pause/Play" button #2111

Merged
merged 1 commit into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ public void onWindowClosed() {
mTray.setAddWindowVisible(mWindows.canOpenNewWindow());
updateWidget(mTray);
}

@Override
public void onWindowVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {
@CPULevelFlags int cpuLevel = mWindows.isVideoAvailable() ? WidgetManagerDelegate.CPU_LEVEL_HIGH :
WidgetManagerDelegate.CPU_LEVEL_NORMAL;

queueRunnable(() -> setCPULevelNative(cpuLevel));
}
});

// Create Browser navigation widget
Expand Down Expand Up @@ -1412,11 +1420,6 @@ public float getCylinderDensity() {
return mCurrentCylinderDensity;
}

@Override
public void setCPULevel(int aCPULevel) {
queueRunnable(() -> setCPULevelNative(aCPULevel));
}

@Override
public boolean canOpenNewWindow() {
return mWindows.canOpenNewWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ private void dumpAllState() {
for (GeckoSession.ContentDelegate listener: mContentListeners) {
dumpState(listener);
}

for (VideoAvailabilityListener listener: mVideoAvailabilityListeners) {
dumpState(listener);
}
}

private void dumpState(GeckoSession.NavigationDelegate aListener) {
Expand All @@ -213,6 +217,10 @@ private void dumpState(GeckoSession.ContentDelegate aListener) {
aListener.onTitleChange(mState.mSession, mState.mTitle);
}

private void dumpState(VideoAvailabilityListener aListener) {
aListener.onVideoAvailabilityChanged(mState.mMediaElements != null && mState.mMediaElements.size() > 0);
}

public void setPermissionDelegate(GeckoSession.PermissionDelegate aDelegate) {
mPermissionDelegate = aDelegate;
}
Expand Down Expand Up @@ -270,6 +278,7 @@ public void removeTextInputListener(GeckoSession.TextInputDelegate aListener) {

public void addVideoAvailabilityListener(VideoAvailabilityListener aListener) {
mVideoAvailabilityListeners.add(aListener);
dumpState(aListener);
}

public void removeVideoAvailabilityListener(VideoAvailabilityListener aListener) {
Expand Down Expand Up @@ -493,6 +502,10 @@ public boolean isSecure() {
return mState.mSecurityInformation != null && mState.mSecurityInformation.isSecure;
}

public boolean isVideoAvailable() {
return mState.mMediaElements != null && mState.mMediaElements.size() > 0;
}

public Media getFullScreenVideo() {
for (Media media: mState.mMediaElements) {
if (media.isFullscreen()) {
Expand Down Expand Up @@ -1157,10 +1170,8 @@ public void onMediaAdd(@NonNull GeckoSession aSession, @NonNull MediaElement ele
Media media = new Media(element);
mState.mMediaElements.add(media);

if (mState.mMediaElements.size() == 1) {
for (VideoAvailabilityListener listener: mVideoAvailabilityListeners) {
listener.onVideoAvailabilityChanged(true);
}
for (VideoAvailabilityListener listener: mVideoAvailabilityListeners) {
listener.onVideoAvailabilityChanged(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {

@Override
public void setVisible(boolean aIsVisible) {
if (mVisible == aIsVisible) {
if (mVisible == aIsVisible || mWidgetManager == null) {
return;
}
mVisible = aIsVisible;
Expand Down Expand Up @@ -179,14 +179,18 @@ public void setInsecureVisibility(int visibility) {
}

public void mediaAvailabilityChanged(boolean available) {
mBinding.setIsMediaAvailable(false);
if (mMedia != null) {
mMedia.removeMediaListener(mMediaDelegate);
}
if (available) {
mMedia = mAttachedWindow.getSession().getFullScreenVideo();
if (mMedia != null) {
mBinding.setIsMediaAvailable(true);
mBinding.setIsMediaPlaying(mMedia.isPlaying());
mMedia.removeMediaListener(mMediaDelegate);
mMedia.addMediaListener(mMediaDelegate);
}
} else {
mBinding.setIsMediaAvailable(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ interface WorldClickListener {
void resetUIYaw();
void setCylinderDensity(float aDensity);
float getCylinderDensity();
void setCPULevel(@VRBrowserActivity.CPULevelFlags int aCPULevel);
void addFocusChangeListener(@NonNull FocusChangeListener aListener);
void removeFocusChangeListener(@NonNull FocusChangeListener aListener);
void addPermissionListener(PermissionListener aListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public interface WindowListener {
default void onFocusRequest(@NonNull WindowWidget aWindow) {}
default void onBorderChanged(@NonNull WindowWidget aWindow) {}
default void onSessionChanged(@NonNull Session aOldSession, @NonNull Session aSession) {}
default void onVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {}
}

public WindowWidget(Context aContext, int windowId, boolean privateMode) {
Expand Down Expand Up @@ -1472,13 +1473,13 @@ public void onFirstContentfulPaint(@NonNull GeckoSession session) {

@Override
public void onVideoAvailabilityChanged(boolean aVideosAvailable) {
mWidgetManager.setCPULevel(aVideosAvailable ?
WidgetManagerDelegate.CPU_LEVEL_HIGH :
WidgetManagerDelegate.CPU_LEVEL_NORMAL);

if (mTitleBar != null) {
mTitleBar.mediaAvailabilityChanged(aVideosAvailable);
}

for (WindowListener listener: mListeners) {
listener.onVideoAvailabilityChanged(this);
}
}

// GeckoSession.NavigationDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public interface Delegate {
void onWindowBorderChanged(@NonNull WindowWidget aChangeWindow);
void onWindowsMoved();
void onWindowClosed();
void onWindowVideoAvailabilityChanged(@NonNull WindowWidget aWindow);
}

public Windows(Context aContext) {
Expand Down Expand Up @@ -442,6 +443,16 @@ public boolean isInPrivateMode() {
return mPrivateMode;
}

public boolean isVideoAvailable() {
for (WindowWidget window: getCurrentWindows()) {
if (window.getSession().isVideoAvailable()) {
return true;
}
}

return false;
}

public void enterImmersiveMode() {
if (!isInPrivateMode()) {
for (WindowWidget window: mRegularWindows) {
Expand Down Expand Up @@ -1090,7 +1101,13 @@ public void onBorderChanged(WindowWidget aWindow) {
if (mDelegate != null) {
mDelegate.onWindowBorderChanged(aWindow);
}
}

@Override
public void onVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {
if (mDelegate != null) {
mDelegate.onWindowVideoAvailabilityChanged(aWindow);
}
}

@Override
Expand Down