Skip to main content
ARShow
 首页 » 资源教程

Google vr sdk的使用

2016年09月09日 23:38:12101890

效果图

Google vr sdk的使用 资源教程 第1张Google vr sdk的使用 资源教程 第2张


导入sdk前先修改相应参数

Google vr sdk的使用 资源教程 第3张

Google vr sdk的使用 资源教程 第4张

引入

Google vr sdk的使用 资源教程 第5张

依赖

Google vr sdk的使用 资源教程 第6张


VRPlayActivity

public classVrActivity extendsActivity{
   
@InjectView(R.id.video_view)
    VrVideoView
videoView;
   
@InjectView(R.id.seek_bar)
    SeekBar
seekBar;
    private static final
String STATE_PROGRESS_TIME= "progressTime";
    private static final
String STATE_IS_PAUSED= "isPaused";
    private static final
String STATE_VIDEO_DURATION= "videoDuration";
    private int
loadVideoStatus =LOAD_VIDEO_STATUS_UNKNOWN;
    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 boolean
isPaused =false;
    private
VideoLoaderTask backgroundVideoLoaderTask;
    private
VrVideoView.Options videoOptions= new VrVideoView.Options();
    private
Uri fileUri;

   
@Override
   
protected void onCreate(BundlesavedInstanceState) {
       
super.onCreate(savedInstanceState);
       
setContentView(R.layout.vr_activity);
       
ButterKnife.inject(this);
       
seekBar.setOnSeekBarChangeListener(newSeekBarListener());
       
videoView.setEventListener(newActivityEventListener());
       
loadVideoStatus =LOAD_VIDEO_STATUS_UNKNOWN;
       
handleIntent(getIntent());
   
}

   
private class ActivityEventListenerextendsVrVideoEventListener {

       
@Override
       
public void onLoadSuccess() {
           
seekBar.setMax((int)videoView.getDuration());
       
}

       
@Override
       
public void onClick() {
            togglePause()
;
       
}

       
@Override
       
public void onNewFrame() {
            
seekBar.setProgress((int)videoView.getCurrentPosition());
       
}

    }

   
@Override
   
public void onRestoreInstanceState(BundlesavedInstanceState) {
       
super.onRestoreInstanceState(savedInstanceState);

        long
progressTime = savedInstanceState.getLong(STATE_PROGRESS_TIME);
       
videoView.seekTo(progressTime);
       
seekBar.setMax((int) savedInstanceState.getLong(STATE_VIDEO_DURATION));
       
seekBar.setProgress((int) progressTime);

       
isPaused = savedInstanceState.getBoolean(STATE_IS_PAUSED);
        if
(isPaused) {
           
videoView.pauseVideo();
       
}
    }

   
private class SeekBarListenerimplementsSeekBar.OnSeekBarChangeListener {
       
@Override
       
public void onProgressChanged(SeekBarseekBar, intprogress, booleanfromUser){
           
if (fromUser){
               
videoView.seekTo(progress);
           
} // elsethis was from the ActivityEventHandler.onNewFrame()'s seekBar.setProgressupdate.
       
}

       
@Override
       
public void onStartTrackingTouch(SeekBarseekBar) {
        }

       
@Override
       
public void onStopTrackingTouch(SeekBarseekBar) {
        }
    }

   
private void handleIntent(Intent intent){
       
if (Intent.ACTION_VIEW.equals(intent.getAction())) {

           
fileUri =intent.getData();
            if
(fileUri==null) {
                Log.w(
"TAG","Nodata uri specified. Use \"-d /path/filename\".");
           
} else{
                Log.i(
"TAG","Usingfile " +fileUri.toString());
           
}

           
videoOptions.inputFormat= intent.getIntExtra("inputFormat",VrVideoView.Options.FORMAT_DEFAULT);
           
videoOptions.inputType= intent.getIntExtra("inputType",VrVideoView.Options.TYPE_MONO);
       
} else{
            Log.i(
"TAG","Intentis not ACTION_VIEW. Using the default video.");
           
fileUri =null;
       
}
       
if (backgroundVideoLoaderTask!= null) {
           
// Cancel any task from a previous intent sent to thisactivity.
            
backgroundVideoLoaderTask.cancel(true);
       
}
       
backgroundVideoLoaderTask =new VideoLoaderTask();
       
backgroundVideoLoaderTask.execute(Pair.create(fileUri,videoOptions));
   
}

   
@Override
   
protected void onPause() {
       
super.onPause();
       
videoView.pauseRendering();
       
isPaused =true;
   
}

   
@Override
   
protected void onResume() {
       
super.onResume();
       
videoView.resumeRendering();
   
}

   
@Override
   
protected void onDestroy() {
       
videoView.shutdown();
        super
.onDestroy();
   
}

   
private void togglePause() {
       
if (isPaused) {
           
videoView.playVideo();
       
} else{
           
videoView.pauseVideo();
       
}
       
isPaused = !isPaused;
   
}

   
class VideoLoaderTaskextendsAsyncTask<Pair<Uri,VrVideoView.Options>,Void, Boolean> {
       
@Override
       
protected BooleandoInBackground(Pair<Uri,VrVideoView.Options>...fileInformation) {

           
// No intent was specified, so we default to playing thelocal stereo-over-under video.
           
final VrVideoView.Optionsoptions =new VrVideoView.Options();
           
/**设置视频的播放焦点*/
           
options.inputType=VrVideoView.Options.TYPE_MONO;
           
Intent intent = getIntent();
            final
String uri = intent.getStringExtra("uri");
           
Log.i("TAG",uri + "uri");
            if
(uri != null) {
                runOnUiThread(
new Runnable() {
                   
@Override
                   
public void run() {
                       
try {
                           
videoView.loadVideo(Uri.parse(uri),options);
                       
} catch(IOException e) {
                           e.printStackTrace()
;
                       
}
                    }
                })
;

//                   videoView.loadVideoFromAsset("congo.mp4", options);
           
}


           
return true;
       
}
    }

 xml布局

<?xml version="1.0"encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
android:orientation="vertical"android:layout_width="match_parent"
   
android:layout_height="match_parent">
   <com.google.vr.sdk.widgets.video.VrVideoView
       
android:id="@+id/video_view"
       
android:layout_width="match_parent"
       
android:layout_height="250dip"/>

   
<!-- Seeking UI & progress indicator.-->
   
<SeekBar
       
android:id="@+id/seek_bar"
       
style="?android:attr/progressBarStyleHorizontal"
       
android:layout_height="32dp"
       
android:layout_width="match_parent"
       
/>
</LinearLayout>



评论列表暂无评论
发表评论