VR View sample code

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.

VR View Sample apps

There are two sample apps which demonstrate the VR View functionality in the SDK: simplepanowidget and simplevideowidget. Both of these samples are single activity applications that display an embedded panoramic image or video using VrPanoramaView and VrVideoView, respectively.


The simplepanowidget and simplevideowidget samples with their VR Views in embed mode.

They allow the user to view different parts of the panorama by rotating their phone. The simplevideowidget 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 simplepanowidget res/layout/main_layout.xml:

      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 simplevideowidget sample uses a very similar flow to simplepanowidget. 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 spatialmedia metadata.