Skip to content

Commit

Permalink
fix a exception
Browse files Browse the repository at this point in the history
  • Loading branch information
autoandshare committed Mar 5, 2021
1 parent 1c42290 commit a17ed1d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
27 changes: 17 additions & 10 deletions src/main/java/autoandshare/headvr/activity/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ private Boolean updateEyeDistance(int i) {

private void updateScreenSize(int i) {
updateSettingWithId(Setting.id.VideoSize, i);
videoRenderer.updateVideoPosition();
videoRenderer.updateVideoPositionAndOthers();
}

private void updateScreenVertical(int i) {
updateSettingWithId(Setting.id.VerticalDistance, i);
}

private Boolean playMediaFromList(int offset) {
lastEventTime = System.currentTimeMillis();
if (!playList.isReady()) {
videoRenderer.getState().message = "Loading play list";
} else {
Expand Down Expand Up @@ -178,7 +179,7 @@ public void onResume() {

setBrightness();
if (videoRenderer != null) {
videoRenderer.updateVideoPosition();
videoRenderer.updateVideoPositionAndOthers();
}
}

Expand Down Expand Up @@ -244,12 +245,16 @@ public void onDrawEye(Eye eye) {
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

if (uiVisible) {
basicUI.glDraw(eye, videoRenderer.getState(), headControl,
(playList != null) ? playList.currentIndex() : "");
}
try {
if (uiVisible) {
basicUI.glDraw(eye, videoRenderer.getState(), headControl,
(playList != null) ? playList.currentIndex() : "");
}

videoRenderer.glDraw(eye);
videoRenderer.glDraw(eye);
} catch (Exception ex) {
Log.e(TAG, "glDraw got exception ", ex);
}
}

@Override
Expand Down Expand Up @@ -303,7 +308,7 @@ public boolean dispatchKeyEvent(KeyEvent event) {
Log.d(TAG, "got key event " + event.toString());
Event e = KeyControl.processKeyEvent(event,
(!Setting.DisableExtraFunction) &&
(videoRenderer != null) && videoRenderer.frameVisibleAndPaused());
(videoRenderer != null) && videoRenderer.frameVisibleAndPaused());
if (e.action != Actions.NoAction) {
appendEvent(e);
return true;
Expand Down Expand Up @@ -357,8 +362,10 @@ public interface Consumer<T> {

private void setupActionTable() {
actionTable = new HashMap<>();
actionTable.put(Actions.NoAction, (e) -> {});
actionTable.put(Actions.PartialAction, (e) -> {});
actionTable.put(Actions.NoAction, (e) -> {
});
actionTable.put(Actions.PartialAction, (e) -> {
});
actionTable.put(Actions.PlayOrPause, (e) -> videoRenderer.pauseOrPlay());
actionTable.put(Actions.NextFile, (e) -> nextFile());
actionTable.put(Actions.PrevFile, (e) -> prevFile());
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/autoandshare/headvr/lib/VideoRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@ private float getOffsetWithoutLength() {
}

public Boolean toggleForce2D() {
if ((this.mw != null) && !state.videoType.isMono()) {
if ((this.mw != null) && (state.videoType != null) && !state.videoType.isMono()) {
state.force2D = !state.force2D;
videoProperties.setForce2D(propertyKey, state.force2D);
updatePositionRequested = true;
state.message = (state.force2D ? "Enable" : "Disable") + " Force2D";
}

Expand Down Expand Up @@ -214,12 +213,8 @@ public static class State {
private VRTexture2D videoScreen;
private MeshExt mesh;

public static boolean drawSameImage() {
return state.force2D || state.videoType.isMono();
}

public static boolean useRightTexture(int eyeType) {
return VideoRenderer.drawSameImage() || (eyeType == Eye.Type.RIGHT);
return eyeType == Eye.Type.RIGHT || VideoRenderer.state.force2D;
}

public static float getCurrentEyeDistance() {
Expand All @@ -241,7 +236,7 @@ private void getLayoutFromName(String name, VideoType videoType) {
if (matcher.find()) {
if (matcher.group(2).toLowerCase().startsWith("h") &&
(videoType.aspect == VideoType.Aspect.Auto)) {
videoType.aspect = VideoType.Aspect.Half;
videoType.aspect = VideoType.Aspect.Half;
} else if (matcher.group(2).toLowerCase().startsWith("f") &&
(videoType.aspect == VideoType.Aspect.Auto)) {
videoType.aspect = VideoType.Aspect.Full;
Expand Down Expand Up @@ -320,16 +315,18 @@ private String[] getLangKeywords(Setting.id id) {
}
return null;
}

private String[] getAudioKeywords() {
return getLangKeywords(Setting.id.AudioLanguageKeywords);
}

private String[] getSubtitleKeyword() {
return getLangKeywords(Setting.id.SubtitleLanguageKeywords);
}

private void setTrack(MediaPlayer.TrackDescription[] tracks, String[] keywords,
int pref,
VideoActivity.Consumer<Integer> setFunc) {
int pref,
VideoActivity.Consumer<Integer> setFunc) {

if (tracks == null || keywords == null || keywords.length == 0) {
return;
Expand Down Expand Up @@ -488,7 +485,7 @@ private void resetState() {
state.message = null;
}

public void updateVideoPosition() {
public void updateVideoPositionAndOthers() {
if (framesCount == 0) {
return;
}
Expand Down Expand Up @@ -520,8 +517,9 @@ public void updateVideoPosition() {
private boolean isSBSFullByGuess(float heightWidthRatio) {
return heightWidthRatio < 1f / 3;
}

private boolean isTABFullByGuess(float heightWidthRatio) {
return heightWidthRatio > 3.3f / 4;
return heightWidthRatio > 3.3f / 4;
}

private void setScreenSize() {
Expand All @@ -537,7 +535,7 @@ private void setScreenSize() {
heightWidthRatio *= 2;
}

} else if (state.videoType.isTAB() && !state.videoType.isHalf() ) {
} else if (state.videoType.isTAB() && !state.videoType.isHalf()) {
if (state.videoType.isFull() || isTABFullByGuess(heightWidthRatio)) {
heightWidthRatio /= 2;
}
Expand Down Expand Up @@ -585,7 +583,7 @@ private void updateStates() {
restartIfNeeded();
}
if (updatePositionRequested) {
updateVideoPosition();
updateVideoPositionAndOthers();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public VRSurface(float width, float height, float distance,
PointF topLeft, int widthPixel, int heightPixel) {
vrTexture2D = new VRTexture2D();
vrTexture2D.verticalFixed = true;
vrTexture2D.setMediaType(Mesh.MEDIA_MONOSCOPIC);
vrTexture2D.updatePositions(
width, height, distance,
topLeft);
Expand Down

0 comments on commit a17ed1d

Please sign in to comment.