diff --git a/src/main/java/autoandshare/headvr/activity/VideoActivity.java b/src/main/java/autoandshare/headvr/activity/VideoActivity.java index 221f99d..f79375f 100644 --- a/src/main/java/autoandshare/headvr/activity/VideoActivity.java +++ b/src/main/java/autoandshare/headvr/activity/VideoActivity.java @@ -3,6 +3,8 @@ import android.net.Uri; import android.opengl.GLES20; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import android.view.WindowManager; @@ -139,12 +141,16 @@ private Boolean playMediaFromList(int offset) { if (mw == null) { videoRenderer.getState().errorMessage = "Invalid play list"; } else { + hideUI = true; videoRenderer.playUri(mw); + new Handler(Looper.getMainLooper()).postDelayed(() -> hideUI = false, 1000); } } return true; } + private boolean hideUI = false; + private Boolean prevFile() { return playMediaFromList(-1); } @@ -243,7 +249,7 @@ public void onDrawEye(Eye eye) { videoRenderer.glDraw(eye); - if (uiVisible) { + if ((!hideUI) && uiVisible) { basicUI.glDraw(eye, videoRenderer.getState(), headControl, (playList != null) ? playList.currentIndex() : ""); } diff --git a/src/main/java/autoandshare/headvr/lib/VideoRenderer.java b/src/main/java/autoandshare/headvr/lib/VideoRenderer.java index 3e51210..4fd1f42 100644 --- a/src/main/java/autoandshare/headvr/lib/VideoRenderer.java +++ b/src/main/java/autoandshare/headvr/lib/VideoRenderer.java @@ -281,6 +281,7 @@ public VideoRenderer(Activity activity) { private boolean ended = false; private boolean frameReady = false; private boolean positionUpdated = false; + private int retry = 0; private ParcelFileDescriptor fd; @@ -294,6 +295,7 @@ public void playUri(MediaWrapper mw) { ended = false; frameReady = false; positionUpdated = false; + retry = 0; resetState(); this.mw = mw; @@ -338,12 +340,15 @@ public void playUri(MediaWrapper mw) { mPlayer.setMedia(m); m.release(); - mPlayer.play(); + playAndSeek(); + + switchingVideo = false; + } + private void playAndSeek() { + mPlayer.play(); mPlayer.setPosition(videoProperties.getPosition(propertyKey)); state.playing = true; - - switchingVideo = false; } private void resetState() { @@ -515,7 +520,12 @@ public void onEvent(MediaPlayer.Event event) { case MediaPlayer.Event.Stopped: state.playerState = "Stopped"; if ((!state.videoLoaded) && (mPlayer.getLength() == 0)) { - state.playerState = "Failed to open"; + if (retry < 3) { + mPlayer.stop(); + playAndSeek(); + retry += 1; + } else + state.playerState = "Failed to open"; } break;