I am making a VR Android application using VrVideoView. I want to force "close(X, back button)" to be clicked after the video is played. That is, I want to return to MainActivity after the video finishes. Below is the codes I've tried. However, I did not go back to MainActivity after the video was finished. If you know how, please let me know.
1.
videoWidgetView.pauseVideo();
videoWidgetView.seekTo(0);
videoWidgetView.shutdown();
2.
videoWidgetView.pauseVideo();
videoWidgetView.seekTo(0);
finishActivity(0);
3.
videoWidgetView.pauseVideo();
videoWidgetView.seekTo(0);
findViewById(R.id.ui_back_button).performClick();
4.
videoWidgetView.pauseVideo();
videoWidgetView.seekTo(0);
Field f;
try {
f =videoWidgetView.getClass().getSuperclass().getDeclaredField("vrUiLayer");
f.setAccessible(true);
UiLayer vrLayer = (UiLayer) f.get(videoWidgetView);
vrLayer.getView().findViewById(R.id.ui_back_button).performClick();
}
catch (NoSuchFieldException e) {
e.printStackTrace();
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
Just override OnDestroy
method and add these lines into it:
@Override
protected void onDestroy() {
videoWidgetView.shutdown();
super.onDestroy();
}
Then call onDestroy()
method in onCompletion
method:
@Override
public void onCompletion() {
videoWidgetView.seekTo(0);
videoWidgetView.pauseVideo();
onDestroy();
}
Hope it works :)