B4A Library Google VR

This library wraps the 'pano' and 'video' packages from the Google VR for Android API.
Enabling you to display mono and stereo 360° VR images and videos in your projects.

Look at the VrPanoramaView and VrVideoView objects, these are the View objects you'll use in your project.
Each View has a similarly named Options object that along with the VrWidgetViewDisplayMode object contain constants and configurations values required by various library methods.

GoogleVr
Version:
1.20
  • VrConstants
    Fields:
    • VrPanoramaViewOptions As VrPanoramaViewOptions
    • VrVideoViewOptions As VrVideoViewOptions
    • VrWidgetViewDisplayMode As VrWidgetViewDisplayMode
  • VrPanoramaView
    Events:
    • Click
    • DisplayModeChanged (NewDisplayMode As Int)
    • LoadError (ErrorMessage As String)
    • LoadSuccess
    Fields:
    • GRAVITY_BOTTOM As Int
    • GRAVITY_CENTER As Int
    • GRAVITY_CENTER_HORIZONTAL As Int
    • GRAVITY_CENTER_VERTICAL As Int
    • GRAVITY_FILL As Int
    • GRAVITY_FILL_HORIZONTAL As Int
    • GRAVITY_FILL_VERTICAL As Int
    • GRAVITY_LEFT As Int
    • GRAVITY_NO_GRAVITY As Int
    • GRAVITY_RIGHT As Int
    • GRAVITY_TOP As Int
    • ba As BA
    Methods:
    • AddView (View As View, Width As Int, Height As Int, Gravity As Int)
    • BringToFront
    • GetAllViewsRecursive As IterableList
    • GetHeadRotation (YawAndPitch() As Float)
      Provides yaw and pitch angles corresponding to where the user is looking.

      yaw is the rotation along the vertical (y) axis.
      Values are in the [-180, 180] range where:
      • 0 - looking straight at the initial image orientation.
      • 90 - looking 90 degrees to the right.
      • -90 - looking 90 degrees to the left.
      • -180 or 180 - looking in the direction opposite to the initial one

      pitch is the rotation along the right (x) axis previously rotated by yaw.
      Values are in the [-90, 90] range where:
      • 0 - looking straight, level with the ground.
      • 90 - looking up
      • -90 - looking down

      When pitch approaches 90 or -90, yaw values are reset to zero as computing the yaw values becomes numerically unstable.
    • GetView (Index As Int) As ConcreteViewWrapper
    • Initialize
      Initialize the VrWidgetView.
    • Initialize2 (EventName As String)
      Initialize the VrWidgetView and set an event listener.
      (Shortcut for calling Initialize then SetEventListener methods).
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • LoadImageFromBitmap (Bitmap1 As Bitmap, InputType As Int)
      Asynchronously loads a pano image using the given bitmap.
      The image to load should be encoded in ARGB_8888 or RGB_565 format.
      See format description at android.graphics.Bitmap.Config
      Event LoadError or LoadSuccess will be raised.
    • PauseRendering
      Pauses 3D rendering and tracking.
      This should be called in the activity's onPause() method.
    • RemoveAllViews
    • RemoveView
    • RemoveViewAt (Index As Int)
    • RequestFocus As Boolean
    • ResumeRendering
      Resumes 3D rendering and tracking.
      This should be called in the activity's onResume() method.
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetElevationAnimated (Duration As Int, Elevation As Float)
    • SetEventListener (EventName As String)
      Set an event listener.
      Events raised:
      Click - Called when the view has been clicked.
      DisplayModeChanged - Called when the view's display mode has changed.
      LoadError - There was an error when loading the resource.
      LoadSuccess - The resource was successfully loaded and rendering has started.
      Pass Null to clear an existing event listener.
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • Shutdown
      Shuts rendering down and releases associated memory.
      Make sure you call this method before the activity is destroyed to reclaim memory. This can be typically called in the activity's onDestroy() method.
      PauseRendering() must be called prior to this function.
      The View should not be used anymore after this method has been called.
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Constants As VrConstants [read only]
      Returns the VrConstants object.
    • DisplayMode As Int
      Get or Set the widget's DisplayMode.
      Use the VrWidgetViewDisplayMode constants to set this value.
    • Elevation As Float
    • Enabled As Boolean
    • FullscreenButtonEnabled As Boolean [write only]
      Shows or hides the button to transition to fullscreen mode.
      This button is visible by default whenever the View is in embedded or in stereo mode.
    • Height As Int
    • InfoButtonEnabled As Boolean [write only]
      Shows or hides the show info button.
      The button is visible by default.
    • Left As Int
    • NumberOfViews As Int [read only]
    • Padding()() As Int
    • Parent As Object [read only]
    • StereoModeButtonEnabled As Boolean [write only]
      Shows or hides the button to transition to stereo mode.
      This button is visible by default whenever the View is in embedded or fullscreen mode.
      This button will never be shown on phones which don't have the necessary sensors for stereo mode -- i.e. a gyroscope and accelerometer.
    • Tag As Object
    • Top As Int
    • TouchTrackingEnabled As Boolean [write only]
      Enables or disabled tracking of the view via touch gestures. Only the heading angle can be controlled by touch. This is true by default.
      Regardless of how this is set, touch tracking will be inactive in fullscreen stereo mode.
    • Visible As Boolean
    • Width As Int
  • VrPanoramaViewOptions
    Fields:
    • TYPE_MONO As Int
    • TYPE_STEREO_OVER_UNDER As Int
  • VrVideoView
    Events:
    • Click
    • Completion
    • DisplayModeChanged (NewDisplayMode As Int)
    • LoadError (ErrorMessage As String)
    • LoadSuccess
    • NewFrame
    Fields:
    • GRAVITY_BOTTOM As Int
    • GRAVITY_CENTER As Int
    • GRAVITY_CENTER_HORIZONTAL As Int
    • GRAVITY_CENTER_VERTICAL As Int
    • GRAVITY_FILL As Int
    • GRAVITY_FILL_HORIZONTAL As Int
    • GRAVITY_FILL_VERTICAL As Int
    • GRAVITY_LEFT As Int
    • GRAVITY_NO_GRAVITY As Int
    • GRAVITY_RIGHT As Int
    • GRAVITY_TOP As Int
    • ba As BA
    Methods:
    • AddView (View As View, Width As Int, Height As Int, Gravity As Int)
    • BringToFront
    • GetAllViewsRecursive As IterableList
    • GetHeadRotation (YawAndPitch() As Float)
      Provides yaw and pitch angles corresponding to where the user is looking.

      yaw is the rotation along the vertical (y) axis.
      Values are in the [-180, 180] range where:
      • 0 - looking straight at the initial image orientation.
      • 90 - looking 90 degrees to the right.
      • -90 - looking 90 degrees to the left.
      • -180 or 180 - looking in the direction opposite to the initial one

      pitch is the rotation along the right (x) axis previously rotated by yaw.
      Values are in the [-90, 90] range where:
      • 0 - looking straight, level with the ground.
      • 90 - looking up
      • -90 - looking down

      When pitch approaches 90 or -90, yaw values are reset to zero as computing the yaw values becomes numerically unstable.
    • GetView (Index As Int) As ConcreteViewWrapper
    • Initialize
      Initialize the VrWidgetView.
    • Initialize2 (EventName As String)
      Initialize the VrWidgetView and set an event listener.
      (Shortcut for calling Initialize then SetEventListener methods).
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • LoadVideo (Path As String, VideoFormat As Int, VideoType As Int)
      Asynchronously loads a pano video from the given Path.
      The Path can be a path to a local file or a remote URL with an <i>http</i> or <i>https</i> scheme.
      VideoFormat and VideoType are constants from the VrVideoViewOptions object.
      Event LoadError or LoadSuccess will be raised.
    • LoadVideoFromAsset (Path As String, VideoFormat As Int, VideoType As Int)
      Asynchronously loads a pano video from the given file in the assets of the apk.
      If the video isn't located the assets, the general LoadVideo(Path As String, VideoFormat As Int, VideoType As Int) method should be used.
      VideoFormat and VideoType are constants from the VrVideoViewOptions object.
      Event LoadError or LoadSuccess will be raised.
    • PauseRendering
      Pauses 3D rendering and tracking.
      This should be called in the activity's onPause() method.
      This also pauses the video and resumeRendering() will resume rendering tracking but not the video playback.
      If the app wants to resume playing the video it should call PlayVideo() when appropriate.
    • PauseVideo
      Pauses the video if it is playing.
    • PlayVideo
      Starts playing the video as soon as it is loaded.
      Resumes playing a paused video.
    • RemoveAllViews
    • RemoveView
    • RemoveViewAt (Index As Int)
    • RequestFocus As Boolean
    • ResumeRendering
      Resumes 3D rendering and tracking.
      This should be called in the activity's onResume() method.
    • SeekTo (PositionMillis As Long)
      Seeks to a position in the video.
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetElevationAnimated (Duration As Int, Elevation As Float)
    • SetEventListener (EventName As String)
      Set an event listener.
      Events raised:
      Click - Called when the view has been clicked.
      Completion - The video has finished playing.
      DisplayModeChanged - Called when the view's display mode has changed.
      LoadError - There was an error when loading the resource.
      LoadSuccess - The resource was successfully loaded and rendering has started.
      NewFrame - A new frame has been drawn to the screen.
      Pass Null to clear an existing event listener.
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • SetVolume (Volume As Float)
      Sets a multiplier to the volume between 0.0f and 1.0f on the media audio playback.
      This setting persists across multiple videos. Set to 1.0f by default.
      TODO do not use - method not found!
    • Shutdown
      Shuts rendering down and releases associated memory.
      Make sure you call this method before the activity is destroyed to reclaim memory. This can be typically called in the activity's onDestroy() method.
      PauseRendering() must be called prior to this function.
      The View should not be used anymore after this method has been called.
    Permissions:
    • android.permission.INTERNET
    • android.permission.READ_EXTERNAL_STORAGE
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Constants As VrConstants [read only]
      Returns the VrConstants object.
    • CurrentPosition As Long [read only]
      Gets the current position in the video.
      Returns the current position in milliseconds.
    • DisplayMode As Int
      Get or Set the widget's DisplayMode.
      Use the VrWidgetViewDisplayMode constants to set this value.
    • Duration As Long [read only]
      Gets the duration of the video.
      Returns the duration in milliseconds.
    • Elevation As Float
    • Enabled As Boolean
    • FullscreenButtonEnabled As Boolean [write only]
      Shows or hides the button to transition to fullscreen mode.
      This button is visible by default whenever the View is in embedded or in stereo mode.
    • Height As Int
    • InfoButtonEnabled As Boolean [write only]
      Shows or hides the show info button.
      The button is visible by default.
    • Left As Int
    • NumberOfViews As Int [read only]
    • Padding()() As Int
    • Parent As Object [read only]
    • StereoModeButtonEnabled As Boolean [write only]
      Shows or hides the button to transition to stereo mode.
      This button is visible by default whenever the View is in embedded or fullscreen mode.
      This button will never be shown on phones which don't have the necessary sensors for stereo mode -- i.e. a gyroscope and accelerometer.
    • Tag As Object
    • Top As Int
    • TouchTrackingEnabled As Boolean [write only]
      Enables or disabled tracking of the view via touch gestures. Only the heading angle can be controlled by touch. This is true by default.
      Regardless of how this is set, touch tracking will be inactive in fullscreen stereo mode.
    • Visible As Boolean
    • Width As Int
  • VrVideoViewOptions
    Fields:
    • FORMAT_DEFAULT As Int
    • FORMAT_HLS As Int
    • TYPE_MONO As Int
    • TYPE_STEREO_OVER_UNDER As Int
  • VrWidgetViewDisplayMode
    Fields:
    • EMBEDDED As Int
    • FULLSCREEN_MONO As Int
    • FULLSCREEN_STEREO As Int

A minimum android API level of 21 is required in order to use this library.
The library also depends on 4 .aar format libraries from Google:
  • common.aar
  • commonwidget.aar
  • panowidget.aar
  • videowidget.aar
These are included in the Google VR library and (java) demo available at:
https://developers.google.com/vr/android/download.
Look in the libraries folder in the download for the .aar files and then copy them across to your b4a additional libraries folder.

There have been problem with users not downloading the current latest version of the Google VR .aar files (more info HERE).
So the 4 .aar files you require can be downloaded from Google_VR_aar_libs_20170130.zip.
These .aar files are currently version 1.10.0
I'll post a simple example next...

Library files are over 1MB in size so cannot be attached to this post. Instead download them from HERE.
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Is it possible to wrap the controller classes too ? (daydream controller)

Possible yes, but not something i have time to do.
I can make the library source code available if someone else has time to add the other classes.
 

hcm

Member
Licensed User
Longtime User
Hi, looks great! Would it be possible to set a camera view as VRPanoramaView background (using a transparent 360 degrees image) to use this in a simple augmented reality app?
 

hcm

Member
Licensed User
Longtime User
Hi warwound,
I tried your GoogleVR lib and it really works great. Thanks a lot for this.
Actually I would like to use it for a simple AR App, as the yaw/pitch heading is solved very well and graphics is fast.
I already tried a transparent png file with some non-transparent objects and placed it in front of a cam preview panel.
Unfortunately it didn't work, the VrPanoramaView stayed opaque even when declaring its background as transparent.

I found a posting which deals with the same subject and where this is proposed:

"Besides the backgroundColor, set opaque NO for all the sublayers of the carboardView.layer.
It works when vrModeEnabled is NO. I have no idea when vrModeEnabled is YES."


http://stackoverflow.com/questions/...-cardboard-view-scenes-background-to-show-cam


Is there a possibility to set the sublayers to transparent in your library?
Otherwise, could I pay you the work to include it, if it isn't too demanding?
 

warwound

Expert
Licensed User
Longtime User
Is there a possibility to set the sublayers to transparent in your library?

Hi.

Let's start with some basics - then i can better understand what you require.

  • VrPanoramaView and VrVideoView are both derived from VrWidgetView.
  • VrWidgetView is derived from the android FrameLayout.

So i'd guess you want to access one or more methods of the FrameLayout in order to set it's background as transparent.

The code snippet on the stanckoverflow page you linked to isn't java - looks like C++ for Apple devices to me - so isn't an awful lot of help working out which java methods of the FrameLayout need to be called.

Can you experiment using the JavaObject library using code such as this:

B4X:
Dim FrameLayout as JavaObject=MyVrPanoramaView '   here change MyVrPanoramaView to match your code

'   choose a java method to call and choose params to pass to that method
Dim MethodName as String="HERE PUT THE NAME OF THE METHOD YOU WANT TO CALL)
Dim Params() As Object=Array As Object(COMMA SEPARATED LIST OF PARAMS HERE)

FrameLayout.RunMethod(MethodName, Params)

Now a search for "android framelayout transparent" brings various results.
You can try to implement any suggestions found in the results using the JavaObject.
 
  • Like
Reactions: hcm

hcm

Member
Licensed User
Longtime User
Thanks for the explanation and help! You are right, the example refers to iOS, but deals with the same concept/problem.

Hopefully the Javaobject Lib will allow me to find a solution. I managed to have a transparent VrPanoramaView
background so I can see the camera preview behind, but as soon as I load the .png panorama file its transparent
areas are all shown black, so possibibly transparency is not supported. But I will keep trying....
 

b4xscripter

Member
Licensed User
Longtime User
Dear Warwound,
Many thanks for this library!
May I ask you where can I find the working link to download this library and an example?
Thanks a lot!

Best regards
 

b4xscripter

Member
Licensed User
Longtime User
Thank you a lot, Warwound!
I'll try your library and I'll give you my feedback.

Best regards
 

mshafiee110

Active Member
Licensed User
Longtime User
in new version of this lib some errors has been resolved...
plaese update this lib...tnx
 

warwound

Expert
Licensed User
Longtime User
in new version of this lib some errors has been resolved...
plaese update this lib...tnx

What bugs have been fixed?

I'm busy for a while, working and then moving address next week, so don't have time to update the library yet.
 

Pedro Caldeira

Active Member
Licensed User
Longtime User
Great Work.
Is it possible, to have some kind of interactive ccontrols in the panoview ?
To create a VR application, like hovering buttons that select when looking at them, etc ?
 

hcm

Member
Licensed User
Longtime User
Hi Warwound, thanks again for this great lib!
I tested the head tracking method and found it very helpful for my applications. Do you think it would be possible to make a small GetHeadRotation (YawAndPitch() As Float) library without the VR image routines?
Best regards
 

ELCHARO

Member
Licensed User
Longtime User
Nice project!!

A question : if posible to see live videos, from mono sources, like dji api. In this case can fligth my drone with VR googles.

Thanks warwound.
 
Top