在moudle app 的build.gradle文件中 dependencies 节点下添加如下配置:
// 使用google vr 添加的
compile ‘com.google.vr:sdk-base:1.10.0’
compile ‘com.google.vr:sdk-audio:1.10.0’
compile ‘com.google.vr:sdk-videowidget:1.10.0’//使用播放控件需要添加(VrVideoView)
做好如上配置之后,便可以写代码了。
在布局文件中添加播放器控件VrVideoView
<com.google.vr.sdk.widgets.video.VrVideoView
android:id="@+id/video_view"
android:layout_width=“match_parent”
android:layout_height=“match_parent”/>
在Activity中找到控件,设置播放资源即可实现播放。
mVideoView = (VrVideoView) findViewById(R.id.video_view);
VrVideoView.Options option = new VrVideoView.Options();
try {
mVideoView.loadVideo(uri, option);
} catch (IOException e) {
e.printStackTrace();
}
到这我们的播放器就可以播放了,最基本的播放功能就已经实现了。不过这种太简陋了,我们的播放器应该有一些控制按钮,而且是VR播放器应该有VR模式才行,不能是简单的全屏就完了。
下面我们开始正式制作我们的简易版播放器:
activity_player.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout
xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:id="@+id/activity_main"
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=“com.qj.gvr_test.MainActivity”>
<com.google.vr.sdk.widgets.video.VrVideoView
android:id="@+id/video_view"
android:layout_width=“match_parent”
android:layout_height=“match_parent”/>
<LinearLayout
android:id="@+id/video_progress_container"
android:layout_width="@dimen/y1000"
android:layout_height="@dimen/y100"
android:layout_alignParentBottom=“true”
android:layout_centerHorizontal=“true”
android:layout_marginBottom="@dimen/y100"<