Skip to content

Commit

Permalink
hide ui when switching video, retry if play fails
Browse files Browse the repository at this point in the history
  • Loading branch information
autoandshare committed Jun 25, 2019
1 parent b14fbee commit c3a5d82
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() : "");
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/autoandshare/headvr/lib/VideoRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -294,6 +295,7 @@ public void playUri(MediaWrapper mw) {
ended = false;
frameReady = false;
positionUpdated = false;
retry = 0;
resetState();

this.mw = mw;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit c3a5d82

Please sign in to comment.