VR with native android

Overview

When your two of the most interesting things come together, results are nothing but pure fun! This is the case for me here. With Google’s help, VR apps can be developed in native android.

Google has provided a VR SDK for android developers to take a dive into the Virtual Reality. Integrating basic VR functionality with this SDK is easier than falling asleep! 😀

Here is a link for you to quickstart – https://developers.google.com/vr/develop/android/get-started

Let’s get ready for experiencing VR practically, but watch out! 😀

android-vr-image1

Practical

We’ll concentrate on very basics i.e. loading image and video in VR.
Here’s what you need to get started:

  • A VR cardboard
  • An android device with OS 4.4+
  • A 360 image and a 360 video

You can use google’s app – Cardboard Camera (https://play.google.com/store/apps/details?id=com.google.vr.cyclops&hl=en_IN) to capture 360 images.

It’ll produce an image with .vr.jpg extension. But, the SDK supports .jpg. So, we’ll have to convert it and that can be done using this tool – https://storage.googleapis.com/cardboard-camera-converter/index.html

I have captured a view from my vicinity using this app and got it converted to .jpg. This is an image consisting of vertically stacked panoramas. We can also have single image panorama loaded in VR.

android-vr-image2

I also have a demo 360 video.

Place these files in assets folder.

android-vr-image3

The views provided by VR SDK to load 360 media are so light that they can be used within a fragment. Here, for simplicity, we’ll use them with activities. We’ll have 2 activities, 1 for 360 image and another for 360 video.
First of all, include libraries in gradle file for image and video.

I have 2 buttons in my MainActivity.java which redirect me to ImageActivity.java (for 360 image) and VideoActivity.java (for 360 video).

Skipping the regular navigation code, let’s have a look at core part.

1) 360 image

Place VrPanoramaView in xml.

In java file, load the image from assets after converting it into bitmap.

One thing to note here is video options. I have used STEREO_OVER_UNDER type. We have 2 options :

  • STEREO_OVER_UNDER – for image which contains equally sized panoramas, stacked vertically (as the pic captured by me).
  • MONO – for image containing a single panorama.

2) 360 video

Place VrPanoramaView in xml.

Now, just load the video from assets into the view.

We also get a listener for video view. We can loop it by manual coding.

We can even sync a seek bar with video view, depending on our requirements.

Both the views provide an option for Cardboard mode. Here is the screenshot.

android-vr-image4

That’s it…! Didn’t it finish before blinking an eye? 😀

Video

VR at Yudiz

Talking about native app development, we are concentrating on implementing more detailed concepts of VR and are trying to integrate it with AR technologies, like portals.

Conclusion

An innumerable amount of apps can be imagined when such 2 vast concepts, VR and android native collaborate with each other. As this is the future of mobile application development, building such apps, right from the start of an era, will be a lot beneficiary.

mm

Sumeet Rukeja Android Developer

I am an Android Developer at Yudiz Solutions Pvt. Ltd. - a leading Mobile App Development Company. I am passionate about developing android apps and to learn more and more about the deep sea of Android.

Comments are closed.

Top