废话不多说,直接上代码
package com.google.vr.sdk.samples.simplevideowidget;
import com.google.vr.sdk.widgets.video.VrVideoEventListener;
import com.google.vr.sdk.widgets.video.VrVideoView;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
/**
* A test activity that renders a 360 video using {@link VrVideoView}.
* It loads the video in the assets by default. User can use it to load any video files using the
* command:
* adb shell am start -a android.intent.action.VIEW \
* -n com.google.vr.sdk.samples.simplevideowidget/.SimpleVrVideoActivity
* -d file://sdcard/FILENAME.MP4
*/
public class SimpleVrVideoActivity extends Activity {
private static final String TAG = SimpleVrVideoActivity.class.getSimpleName();
/**
* Preserve the video's state when rotating the phone.
*/
private static final String STATE_IS_PAUSED = "isPaused";
private static final String STATE_PROGRESS_TIME = "progressTime";
/**
* The video duration doesn't need to be preserved, but it is saved in this example. This allows
* the seekBar to be configured during {@link #onRestoreInstanceState(Bundle)} rather than waiting
* for the video to be reloaded and analyzed. This avoid UI jank.
*/
private static final String STATE_VIDEO_DURATION = "videoDuration";
/**
* Arbitrary constants and variable to track load status. In this example, this variable should
* only be accessed on the UI thread. In a real app, this variable would be code that performs
* some UI actions when the video is fully loaded.
*/
public static final int LOAD_VIDEO_STATUS_UNKNOWN = 0;
public static final int LOAD_VIDEO_STATUS_SUCCESS = 1;
public static final int LOAD_VIDEO_STATUS_ERROR = 2;
private int loadVideoStatus = LOAD_VIDEO_STATUS_UNKNOWN;
public int getLoadVideoStatus() {
return loadVideoStatus;
}
/** Tracks the file to be loaded across the lifetime of this app. **/
private Uri fileUri;
private VideoLoaderTask backgroundVideoLoaderTask;
/**
* The video view and its custom UI elements.
*/
private VrVideoView videoWidgetView;
/**
* Seeking UI & progress indicator. The seekBar's progress value represents milliseconds in the
* video.
*/
private SeekBar seekBar;
private TextView statusText;
/**
* By default, the video will start playing as soon as it is loaded. This can be changed by using
* {@link VrVideoView#pauseVideo()} after loading the video.
*/
private boolean isPaused = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceS