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

Commit

Permalink
Video projection selection via URL parameter (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored Nov 26, 2018
1 parent 38cd26a commit a9da13e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ public void setMedia(Media aMedia) {
mMedia.setDelegate(this);
}

public void setProjectionSelectorEnabled(boolean aEnabled) {
mMediaProjectionButton.setEnabled(aEnabled);
}

// Media Element delegate
@Override
public void onPlaybackStateChange(MediaElement mediaElement, int playbackState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -90,6 +91,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private MediaControlsWidget mMediaControlsWidget;
private BookmarksWidget mBookmarksWidget;
private Media mFullScreenMedia;
private @VideoProjectionMenuWidget.VideoProjectionFlags Integer mAutoSelectedProjection;

public NavigationBarWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -225,8 +227,13 @@ else if (SessionStore.get().canUnstackSession())
mAudio.playSound(AudioEngine.Sound.CLICK);
}

if (mAutoSelectedProjection != null) {
enterVRVideo(mAutoSelectedProjection);
return;
}
boolean wasVisible = mProjectionMenu.isVisible();
closeFloatingMenus();

if (!wasVisible) {
mProjectionMenu.setVisible(true);
}
Expand Down Expand Up @@ -498,6 +505,7 @@ private void enterVRVideo(@VideoProjectionMenuWidget.VideoProjectionFlags int aP
}
mMediaControlsWidget.setProjectionMenuWidget(mProjectionMenu);
mMediaControlsWidget.setMedia(mFullScreenMedia);
mMediaControlsWidget.setProjectionSelectorEnabled(mAutoSelectedProjection == null);
mWidgetManager.updateWidget(mMediaControlsWidget);
mWidgetManager.showVRVideo(mBrowserWidget.getHandle(), aProjection);
}
Expand Down Expand Up @@ -691,7 +699,11 @@ public void onFullScreen(GeckoSession session, boolean aFullScreen) {
if (mIsResizing) {
exitResizeMode(false);
}

AtomicBoolean autoEnter = new AtomicBoolean(false);
mAutoSelectedProjection = VideoProjectionMenuWidget.getAutomaticProjection(SessionStore.get().getUriFromSession(session), autoEnter);
if (mAutoSelectedProjection != null && autoEnter.get()) {
getHandler().postDelayed(() -> enterVRVideo(mAutoSelectedProjection), 300);
}
} else {
if (mIsInVRVideo) {
exitVRVideo();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.mozilla.vrbrowser.ui.widgets;

import android.content.Context;

import android.net.Uri;
import org.mozilla.vrbrowser.R;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
Expand All @@ -13,14 +14,14 @@ public class VideoProjectionMenuWidget extends MenuWidget {

@IntDef(value = { VIDEO_PROJECTION_3D_SIDE_BY_SIDE, VIDEO_PROJECTION_360,
VIDEO_PROJECTION_360_STEREO, VIDEO_PROJECTION_180,
VIDEO_PROJECTION_180_STEREO_LEFT_RIGTH, VIDEO_PROJECTION_180_STEREO_TOP_BOTTOM })
VIDEO_PROJECTION_180_STEREO_LEFT_RIGHT, VIDEO_PROJECTION_180_STEREO_TOP_BOTTOM })
public @interface VideoProjectionFlags {}

public static final int VIDEO_PROJECTION_3D_SIDE_BY_SIDE = 0;
public static final int VIDEO_PROJECTION_360 = 1;
public static final int VIDEO_PROJECTION_360_STEREO = 2;
public static final int VIDEO_PROJECTION_180 = 3;
public static final int VIDEO_PROJECTION_180_STEREO_LEFT_RIGTH = 4;
public static final int VIDEO_PROJECTION_180_STEREO_LEFT_RIGHT = 4;
public static final int VIDEO_PROJECTION_180_STEREO_TOP_BOTTOM = 5;

public interface Delegate {
Expand Down Expand Up @@ -90,7 +91,7 @@ public void run() {
mItems.add(new MenuItem(R.string.video_mode_180_left_right, R.drawable.ic_icon_videoplayback_180_stereo_leftright, new Runnable() {
@Override
public void run() {
handleClick(VIDEO_PROJECTION_180_STEREO_LEFT_RIGTH);
handleClick(VIDEO_PROJECTION_180_STEREO_LEFT_RIGHT);
}
}));

Expand Down Expand Up @@ -118,4 +119,42 @@ private void handleClick(@VideoProjectionFlags int aVideoProjection) {
public @VideoProjectionFlags int getSelectedProjection() {
return mSelectedProjection;
}

public static @VideoProjectionFlags Integer getAutomaticProjection(String aURL, AtomicBoolean autoEnter) {
if (aURL == null) {
return null;
}

Uri uri = Uri.parse(aURL);
if (uri == null) {
return null;
}

String projection = uri.getQueryParameter("mozVideoProjection");
if (projection == null) {
projection = uri.getQueryParameter("mozvideoprojection");
if (projection == null) {
return null;
}
}
projection = projection.toLowerCase();

autoEnter.set(projection.endsWith("_auto"));

if (projection.startsWith("360")) {
return VIDEO_PROJECTION_360;
} else if (projection.startsWith("360s")) {
return VIDEO_PROJECTION_360_STEREO;
} else if (projection.startsWith("180")) {
return VIDEO_PROJECTION_180;
} else if (projection.startsWith("180lr")) {
return VIDEO_PROJECTION_180_STEREO_LEFT_RIGHT;
} else if (projection.startsWith("180tb")) {
return VIDEO_PROJECTION_180_STEREO_TOP_BOTTOM;
} else if (projection.startsWith("3d")) {
return VIDEO_PROJECTION_3D_SIDE_BY_SIDE;
}

return -1;
}
}

0 comments on commit a9da13e

Please sign in to comment.