超级简单的Google VR SDK播放VR视频

项目引入:

implementation 'com.google.vr:sdk-panowidget:1.30.0'
implementation 'com.google.vr:sdk-videowidget:1.30.0'

布局:



    

    

代码:

public class VideoPlayerActivity extends AppCompatActivity {

    private VrVideoView vr_video;
    private SeekBar seekBar;
    private String url = "http://xxx.mp4";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player);
        vr_video = findViewById(R.id.vr_video);
        seekBar = findViewById(R.id.seek_bar);

        vr_video.setEventListener(new VrVideoEventListener() {
            @Override
            public void onLoadSuccess() {
                super.onLoadSuccess();
                seekBar.setMax((int) vr_video.getDuration());
            }

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

        VrVideoView.Options options = new VrVideoView.Options();
        options.inputType = VrVideoView.Options.TYPE_MONO;
        options.inputFormat = VrVideoView.Options.FORMAT_DEFAULT;
        try {
            vr_video.loadVideo(Uri.parse(url), options);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


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

    @Override
    protected void onPause() {
        super.onPause();
        vr_video.pauseRendering();
    }

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

 

你可能感兴趣的:(Java,移动开发,Android,VR,VR视频,Google,VR,SDK,Android)