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:

Johan Schoeman

Expert
Licensed User
Longtime User
Morning all.
I've fixed the link to the example - though you've figured that out.
What on earth has gone wrong - are you all using the latest version of b4a?
Just wondering if any of you are using an older version and the AdditionalRes attributes for the .aar files are not supported?
Also using V6.5 and Android 23
 

MarcoRome

Expert
Licensed User
Longtime User
That means that the variable name of the VrPanoramaView referenced in the inline java (onDestroy callback) is not found.
Did you change the vaiable name from VrPanoramaView1?

I'll be busy for a bit today then will look at the problems with this library later.

This has been fixed. The most "serious" problem and #5
Thank you for your effort and have nice day
 

Johan Schoeman

Expert
Licensed User
Longtime User
I have tried to "short cut" wrap the panorama view and it comes up with the same error when the B4A project starts i.e java.lang.NoClassDefFoundError: com.google.vrtoolkit.cardboard.proto.nano.CardboardDevice$DeviceParams:
B4X:
LogCat connected to: EA95NNLFUOBE7TJF
--------- beginning of system
--------- beginning of main
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
java.lang.NoClassDefFoundError: com.google.vrtoolkit.cardboard.proto.nano.CardboardDevice$DeviceParams
    at com.google.vr.cardboard.ConfigUtils.readDeviceParamsFromExternalStorage(SourceFile:73)
    at com.google.vr.cardboard.LegacyVrParamsProvider.readDeviceParams(SourceFile:20)
    at com.google.vr.sdk.widgets.common.VrWidgetView.updateViewerName(VrWidgetView.java:741)
    at com.google.vr.sdk.widgets.common.VrWidgetView.updateStereoMode(VrWidgetView.java:497)
    at com.google.vr.sdk.widgets.common.VrWidgetView.resumeRendering(VrWidgetView.java:600)
    at com.google.vr.sdk.samples.simplepanowidget.SimpleVrPanoramaActivity.onResume(SimpleVrPanoramaActivity.java:143)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1267)
    at android.app.Activity.performResume(Activity.java:6186)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3230)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3276)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2619)
    at android.app.ActivityThread.access$800(ActivityThread.java:178)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5643)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
 
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
Hope @warwound give me a hint how to compile example.
 

warwound

Expert
Licensed User
Longtime User
Well this is odd...
I installed latest versions of b4a, java 8 and android sdk on a new Win 10 VM.
Then downloaded the Google VR libs from my link in the first post and then the example project.
I copied the 4 .aar library files from my Win 10 desktop to the VM.

Compiled and installed the apk on an API 19 (KitKat) tablet and it works fine.
I compiled twice, once with android API 21 and again with API 25.

The compilation error previously posted starts here:

at imagineear.api.googlevr.widgets.VrWidgetViewWrapper.ResumeRendering(VrWidgetViewWrapper.java:76)

But as i don't get a compilation error where do i start to debug?

All i have in my b4a additional libraries folder (on the VM) are the GoogleVr .jar and .xml files and the 4 .aar files.
I have had a working version of these 4 .aar files on my desktop for a month or two.
Then, just before i decided to upload the GoogleVr library to the forum, i noticed the android GoogleVr library had been updated.
I updated my desktop version using git on the command line (and updated the wrapper to work with the new version).
Is it possible i have the latest versions of these .aars but the older versions have been downloaded from guthub using the link in post #1?

I've zipped and uploaded my 4 .aar files to HERE.
Can one of you try these .aar files?
 

MarcoRome

Expert
Licensed User
Longtime User
Well this is odd...
I installed latest versions of b4a, java 8 and android sdk on a new Win 10 VM.
Then downloaded the Google VR libs from my link in the first post and then the example project.
I copied the 4 .aar library files from my Win 10 desktop to the VM.

Compiled and installed the apk on an API 19 (KitKat) tablet and it works fine.
I compiled twice, once with android API 21 and again with API 25.

The compilation error previously posted starts here:



But as i don't get a compilation error where do i start to debug?

All i have in my b4a additional libraries folder (on the VM) are the GoogleVr .jar and .xml files and the 4 .aar files.
I have had a working version of these 4 .aar files on my desktop for a month or two.
Then, just before i decided to upload the GoogleVr library to the forum, i noticed the android GoogleVr library had been updated.
I updated my desktop version using git on the command line (and updated the wrapper to work with the new version).
Is it possible i have the latest versions of these .aars but the older versions have been downloaded from guthub using the link in post #1?

I've zipped and uploaded my 4 .aar files to HERE.
Can one of you try these .aar files?
Hi @warwound.
With your aar WORK. Also if i have this message when i compile:

upload_2017-1-30_18-32-9.png


Anyway if i comment i have this FANTASTIC result:


Very very good JOB :D:D:D;)
 

Johan Schoeman

Expert
Licensed User
Longtime User
Your VrPanoramaView1 has been obfuscated into a new name by b4a.

Now your inline java is not referencing the obfuscated name.
OK - got it going on KitKat and Lollipop with the inline Java code being in place! Wow...this is great stuff!

1.png


2.png


3.png


4.png
 
Last edited:

warwound

Expert
Licensed User
Longtime User
So what have we established?
That the link in post #1 links to a previous version of the android library.

The android library changelog can be found here:
GVR SDK and NDK for Android v1.10.0

I cloned the repo using github and got a different version from everyone else?
 

MarcoRome

Expert
Licensed User
Longtime User
So what have we established?
That the link in post #1 links to a previous version of the android library.

The android library changelog can be found here:
GVR SDK and NDK for Android v1.10.0

I cloned the repo using github and got a different version from everyone else?
I don't know what might have happened. But in fact and that the aar libraries 1.10 are fine another no.
Anyway ius important the result :):) and this library is fantastic :D.
Thank you again
 

hanyelmehy

Active Member
Licensed User
Longtime User
Thank you ,its work now ,can i make view in cardboard mode (also i cant find cardboard icon on image)
 
Top