This page is a walkthrough of the VR View samples, which can be found in the
/samples
directory when you download the Google VR SDK
for Android.
Sample apps
There are two sample apps in the SDK that demonstrate how to embed 360° media. Both of samples are single activity applications that display an embedded panoramic image or video:
VrPanoramaView
VrVideoView
The VrPanoramaView and VrVideoView samples with their VR Views in embed mode.
They allow the user to view different parts of the panorama by rotating their phone. The VrVideoView sample also allows the user to pause and play their video by tapping on the VR View, and seek through the video using the slider. The samples expose the fullscreen mode and Cardboard mode buttons in the VR View which allow the user to change modes.
The fullscreen mode is similar to the embed mode but is immersive.
The Cardboard mode allows the user to view the panorama in a Cardboard device like any other Cardboard app.
These two apps also have an additional feature of opening arbitrary panoramas using custom Intents via adb. The syntax for the Intents is documented in the samples' respective Activities, and these Intents can be used to quickly test various media formats.
Overview of the code
A VR View can be included in a layout like any other Android View. This is the
important section of the VrPanoramaView's res/layout/main_layout.xml
:
<com.google.vr.sdk.widgets.pano.VrPanoramaView android:id="@+id/pano_view" android:layout_margin="5dip" android:layout_width="match_parent" android:scrollbars="@null" android:layout_height="250dip" />
Inside the Activity, the primary method is
VrPanoramaView.loadImageFromBitmap()
. Call
it with a standard Android Bitmap
object and an optional
VrPanoramaView.Options
object. The latter is used to configure the format of the image. The Activity
also implements a
VrPanoramaEventListener
which receives events when the load operation succeeds or fails.
The VrVideoView sample uses a very similar flow to VrPanoramaView.
The primary difference is that VrVideoView uses either
loadVideoFromAsset
or
loadVideo
.
While VrPanoramaView
requires the caller to load the image and pass in
configuration information, VrVideoView
accepts a file and reads in the
configuration from the file's
spatial-media
metadata.