B4A Library AndroidVideoCapture - video recorder that is 100% embedded in B4A (6 Jan - new Lib Files in post 48)

The attached project is based on this project (click here). I was asked by @Mashiane to wrap it so that it can be used as a 100% standalone video recorder in B4A. It uses a custom view as the video view. The following applies to the project as it stands at present:

(Read the following and take note of especially point #2 about the folder that you need to create else the app will crash)

1. It can only be used in landscape mode
2. It stores the video files in folder /sdcard/Videos/*.mp4 - there is by default no such directory in the root folder so either create it manually or else add code in the B4A project to check if it exists and if not then create it via B4A code (sure it can be found somewhere on the forum)
3. The Zoom In and Zoom out functions can probably be controlled via a slider...but for this exercise I have added two buttons (Zoom In and Zoom Out)
4. There are a vast number of options as far as specifying video quality is concerned. I have not tested them all - as a matter of fact, I have only tested 2! So, try them and see if there is a difference.
5. The flash light can be switched in two ways (and they also work in conjunction with one another):
a. touch the view while the video recording is active
b. use the "Toggle Flash" button​
6. You will need to add some code to the B4A project to refresh the media files on you device else you will not see the recorded video in the /Videos folder - unless you disconnect your device and reconnect it again (in which case it will then show). Search the forum for how to do the refresh.
7. Take note of the permissions added to the B4A manifest files (some are not required)
I will play around with the code and post updates if and when I have figured out any other useful attributes to add.

Posting the following:
1. B4A project demonstrating the use of the video recorder
2. B4A library files - copy them to your additional library folder.

B4A project launched:
1.png



Video recording started:
2.png



Zoomed In:
3.png


Flash switched on:
4.png



Sample Code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: AndroidVideoCapture
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
    'http://android-er.blogspot.co.za/2011/10/simple-exercise-of-video-capture-using.html

#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.


 
    Private b1, b2, b3, b4 As Button
    Private avc1 As AndroidVideoCapture

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
 
    avc1.MaximimDuration = 120000
    avc1.MaximumFileSize = 10000000
 
    'The video files will be stored in folder /sdcard/Videos/ of your device.
    'Add code to create this folder if the folder does not exist or else just create it manually
    avc1.VideoName = "video1"    'the video will now be stored as "video1.MP4"  
 
    avc1.VideoQuality = avc1.QUALITY_LOW    
 
 
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
 
    avc1.releaseResources

End Sub


Sub b1_Click
 
    avc1.setStartStopRecording
 
End Sub

Sub avc1_flash_toggled (flashOnOrOff As Boolean)
 
    Log("flash status = " & flashOnOrOff)
 
End Sub

Sub b2_Click
 
    avc1.toggleFlash
 
End Sub

Sub b3_Click
 
    avc1.ZoomIn
 
End Sub

Sub b4_Click
 
    avc1.ZoomOut
 
End Sub


The library as it stands at present:

AndroidVideoCapture
Author:
Original project by: Andr.oid Eric, Adapted, modified, and wrapped by: Johan Schoeman
Version: 1
  • AndroidVideoCapture
    Events:
    • flash_toggled (flashOnOrOff as Boolean As )
    Fields:
    • QUALITY_1080P As Int
    • QUALITY_2160P As Int
    • QUALITY_480P As Int
    • QUALITY_720P As Int
    • QUALITY_CIF As Int
    • QUALITY_HIGH As Int
    • QUALITY_HIGH_SPEED_1080P As Int
    • QUALITY_HIGH_SPEED_2160P As Int
    • QUALITY_HIGH_SPEED_480P As Int
    • QUALITY_HIGH_SPEED_720P As Int
    • QUALITY_HIGH_SPEED_HIGH As Int
    • QUALITY_HIGH_SPEED_LOW As Int
    • QUALITY_LOW As Int
    • QUALITY_QCIF As Int
    • QUALITY_QVGA As Int
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • 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)
    • ZoomIn
    • ZoomOut
    • releaseResources
    • setStartStopRecording
    • toggleFlash
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • MaximimDuration As Int [write only]
    • MaximumFileSize As Long [write only]
    • Tag As Object
    • Top As Int
    • VideoName As String [write only]
    • VideoQuality As Int [write only]
    • Visible As Boolean
    • Width As Int
 

Attachments

  • AndroidVideoCaptureLibFiles.zip
    7.6 KB · Views: 754
  • b4aAndroidVideoCapture.zip
    9.2 KB · Views: 765
Last edited:

SJQ

Member
Licensed User
Longtime User
Hi Johan,

Ok, done the above... still getting an error on Activity.LoadLayout("main")

Regards
Steve.

here is the log. :)

Installing file.
** Activity (main) Pause, UserClosed = false **
WakeLock already held.
PackageAdded: package:JHS.AndroidVideoCapture
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
got a camera
Back Facing Camera ID = -1
FRONT CAMERA SUPPORTED = [QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF, QUALITY_LOW, QUALITY_HIGH]
Front Facing Camera ID = 0
Back Facing Camera ID = -1
BackFacingCameraID = -1
FRONT CAMERA SUPPORTED = [QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF, QUALITY_LOW, QUALITY_HIGH]
Front Facing Camera ID = 0
FrontFacingCameraID = 0
Device has no flash
Error occurred on line: 38 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:208)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at JHS.AndroidVideoCapture.main.afterFirstLayout(main.java:102)
at JHS.AndroidVideoCapture.main.access$000(main.java:17)
at JHS.AndroidVideoCapture.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:54)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 21 more
Caused by: java.lang.NoSuchMethodError: android.support.v4.content.ContextCompat.getDrawable
at main.java.org.angmarch.views.NiceSpinner.init(NiceSpinner.java:179)
at main.java.org.angmarch.views.NiceSpinner.<init>(NiceSpinner.java:71)
at nicespinnerwrapper.niceSpinnerWrapper._initialize(niceSpinnerWrapper.java:63)
... 25 more
** Activity (main) Resume **
WakeLock already held.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

Ok, done the above... still getting an error on Activity.LoadLayout("main")

Regards
Steve.

here is the log. :)

Installing file.
** Activity (main) Pause, UserClosed = false **
WakeLock already held.
PackageAdded: package:JHS.AndroidVideoCapture
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
got a camera
Back Facing Camera ID = -1
FRONT CAMERA SUPPORTED = [QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF, QUALITY_LOW, QUALITY_HIGH]
Front Facing Camera ID = 0
Back Facing Camera ID = -1
BackFacingCameraID = -1
FRONT CAMERA SUPPORTED = [QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF, QUALITY_LOW, QUALITY_HIGH]
Front Facing Camera ID = 0
FrontFacingCameraID = 0
Device has no flash
Error occurred on line: 38 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:208)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at JHS.AndroidVideoCapture.main.afterFirstLayout(main.java:102)
at JHS.AndroidVideoCapture.main.access$000(main.java:17)
at JHS.AndroidVideoCapture.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:54)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 21 more
Caused by: java.lang.NoSuchMethodError: android.support.v4.content.ContextCompat.getDrawable
at main.java.org.angmarch.views.NiceSpinner.init(NiceSpinner.java:179)
at main.java.org.angmarch.views.NiceSpinner.<init>(NiceSpinner.java:71)
at nicespinnerwrapper.niceSpinnerWrapper._initialize(niceSpinnerWrapper.java:63)
... 25 more
** Activity (main) Resume **
WakeLock already held.

Thanks Steve. Now we are at least getting somewhere as it is reporting a front camera without a flash. Let me go back to the B4A code and see why it is complaining about line 38.
 
  • Like
Reactions: SJQ

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

Ok, done the above... still getting an error on Activity.LoadLayout("main")

Regards
Steve.

here is the log. :)

Installing file.
** Activity (main) Pause, UserClosed = false **
WakeLock already held.
PackageAdded: package:JHS.AndroidVideoCapture
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
got a camera
Back Facing Camera ID = -1
FRONT CAMERA SUPPORTED = [QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF, QUALITY_LOW, QUALITY_HIGH]
Front Facing Camera ID = 0
Back Facing Camera ID = -1
BackFacingCameraID = -1
FRONT CAMERA SUPPORTED = [QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF, QUALITY_LOW, QUALITY_HIGH]
Front Facing Camera ID = 0
FrontFacingCameraID = 0
Device has no flash
Error occurred on line: 38 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:208)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at JHS.AndroidVideoCapture.main.afterFirstLayout(main.java:102)
at JHS.AndroidVideoCapture.main.access$000(main.java:17)
at JHS.AndroidVideoCapture.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:54)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 21 more
Caused by: java.lang.NoSuchMethodError: android.support.v4.content.ContextCompat.getDrawable
at main.java.org.angmarch.views.NiceSpinner.init(NiceSpinner.java:179)
at main.java.org.angmarch.views.NiceSpinner.<init>(NiceSpinner.java:71)
at nicespinnerwrapper.niceSpinnerWrapper._initialize(niceSpinnerWrapper.java:63)
... 25 more
** Activity (main) Resume **
WakeLock already held.

Steve, you sure you have this file in the B4A project's Objects/res/layout folder?:
spinner_list_item.xml
 

SJQ

Member
Licensed User
Longtime User
Hi Johan,

Yep I can confirm spinner_list_item.xml is present in /Objects/res/layout directory.


BUT... Yay... :)

In my little app I was creating for the Acer unit. video recording... its now working!!!
I don't use the spinner library in my own app.

when I get home I will see if I have the correct versions of the spinner library and let you know.

Thanks again

Regards
Steve
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

Yep I can confirm spinner_list_item.xml is present in /Objects/res/layout directory.


BUT... Yay... :)

In my little app I was creating for the Acer unit. video recording... its now working!!!
I don't use the spinner library in my own app.

when I get home I will see if I have the correct versions of the spinner library and let you know.

Thanks again

Regards
Steve
You are a MACHINE - sharp as a MINORA BLADE! Thanks for helping to get that sorted out! I will remove all the debug info and post a lib without them. Promise I will change nothing else!
 
  • Like
Reactions: SJQ

SJQ

Member
Licensed User
Longtime User
Hi Johan,

Ok, thrown together a little app for the Android Smart Watch and it works great.
Although the camera is on the front of the phone it registers as a back camera (I think its just the way the manufacturers designed it.)
No flash but all worked ok.

Quick Question avc1.releaseResources what does that actually do?

and

if I only want to use Max Duration only and not Maximum File Size do I just set avc1.MaximumFileSize = 0 or omit the setting?
I tried both and it didn't seem to make much difference, but I am unsure if there's any other process running in the library...

Regards
Steve
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

Ok, thrown together a little app for the Android Smart Watch and it works great.
Although the camera is on the front of the phone it registers as a back camera (I think its just the way the manufacturers designed it.)
No flash but all worked ok.

Quick Question avc1.releaseResources what does that actually do?

and

if I only want to use Max Duration only and not Maximum File Size do I just set avc1.MaximumFileSize = 0 or omit the setting?
I tried both and it didn't seem to make much difference, but I am unsure if there's any other process running in the library...

Regards
Steve
avc1.releaseResources releases the camera and media recorder so that other apps can use them. The video recorder ties them up when it is running and if we don't releas them, even when we quit the video recorder, they will not be available for any other app to use.

Make the file size just very large - you specify the number of bytes that you want (so make it like 1000000000 = 1gig)

JS
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

Ok, thrown together a little app for the Android Smart Watch and it works great.
Although the camera is on the front of the phone it registers as a back camera (I think its just the way the manufacturers designed it.)
No flash but all worked ok.

Quick Question avc1.releaseResources what does that actually do?

and

if I only want to use Max Duration only and not Maximum File Size do I just set avc1.MaximumFileSize = 0 or omit the setting?
I tried both and it didn't seem to make much difference, but I am unsure if there's any other process running in the library...

Regards
Steve

EDIT: THE LIBRARY FILES FOR THIS PROJECT ARE IN POST #51
Here it is - cleaned out all the debugging messages and added help to all the public methods...

The library as it stands at present:

AndroidVideoCapture
Author:
Original project by: Andr.oid Eric, Adapted, modified, and wrapped by: Johan Schoeman
Version: 1
  • AndroidVideoCapture
    Events:
    • flash_toggled (flashOnOrOff As Boolean)
    • max_duration_reached (maxdurationreached As Boolean)
    • max_file_size_reached (maxsizereached As Boolean)
    • recording_time_remaining (remainingtime As String)
    Fields:
    • CAMERA_BACK As Int
      The ID of the back facing camera
      If the ID is -1 after initialization then the device does not support a back facing camera
      If the device has front and back cameras then the ID's will be BACK = 0 and FRONT = 1 after initialization
      If the device has a back camera only then the ID's will be BACK = 0 and FRONT = -1 after initialization
      If the device has a front camera only then the ID's will be BACK = -1 and FRONT = 0 after initialization
    • CAMERA_FRONT As Int
      The ID of the front facing camera
      If the ID is -1 after initialization then the device does not support a front facing camera
      If the device has front and back cameras then the ID's will be BACK = 0 and FRONT = 1 after initialization
      If the device has a back camera only then the ID's will be BACK = 0 and FRONT = -1 after initialization
      If the device has a front camera only then the ID's will be BACK = -1 and FRONT = 0 after initialization
    • QUALITY_1080P As Int
    • QUALITY_2160P As Int
    • QUALITY_480P As Int
    • QUALITY_720P As Int
    • QUALITY_CIF As Int
    • QUALITY_HIGH As Int
    • QUALITY_LOW As Int
    • QUALITY_QCIF As Int
    • QUALITY_QVGA As Int
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
      Initialize the videoWrapper class
      Eventname = name of events that this class will raise in B4A
      debugMessages = print debug messages to the log
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • 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)
    • ZoomIn
      Zoom In with increments of 1 at a time
    • ZoomOut
      Zoom Out with decrements of 1 at a time
    • getBackSupportedVideoQuality (cameraId As Int) As ArrayList
      Get a list of the video qualities that the back facing camera supports
      It returns a list of Strings with values such as
      QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF,
      QUALITY_QVGA, QUALITY_LOW, QUALITY_HIGH
      Use for eg avc1.VideoQuality = avc1.QUALITY_720P to set the quality
      that you want to use during recording
    • getFrontSupportedVideoQuality (cameraId As Int) As ArrayList
      Get a list of the video qualities that the front facing camera supports
      It returns a list of Strings with values such as
      QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF,
      QUALITY_QVGA, QUALITY_LOW, QUALITY_HIGH
      Use for eg avc1.VideoQuality = avc1.QUALITY_720P to set the quality
      that you want to use during recording
    • hasCamera As Boolean
      Check if the device has a camera of any sort
    • hasFlash As Boolean
      Check if the device has a flash
    • releaseResources
      Release the camera and media recorder so that they can be
      used by other applications
    • setStartStopRecording
      Toggle stop/start of video recording
    • stopTimer
      it is used in Activity_Pause (UserClosed As Boolean)
      to ensure that the timer used inside the library
      is stopped in case it is still running when the user terminates the activity
    • toggleFlash
      Toggle the flash on/off should the camera in use have a flash
    Properties:
    • AddTimeStampToFileName As Boolean [write only]
      Add a time stamp to the file name
      The video will now be stored as YourVideoName_yyyyMMdd_HHmmss.MP4
    • BackFacingCamera As Int [read only]
      Get the ID of the back facing camera
      If the device has a front and back camera then the ID = 0
      If the device has a back facing camera only then the ID = 0
      It will return the ID as -1 if there is no back facing camera
    • Background As Drawable
    • CameraToUse As Int [write only]
      Set the camera to be use for recording
      For a device with front and back cameras ---> front = 1 and back = 0
      for a device with a front camera only ---> front = 0
      for a device with a back facing camera only ---> back = 0
      Use avc1.BackFacingCamera and avc1.FrontFacingCamera to get the camera ID's
    • Color As Int [write only]
    • Enabled As Boolean
    • FrontFacingCamera As Int [read only]
      Get the ID of the front facing camera
      If the device has a front and back camera then the ID = 1
      If the device has a front facing camera only then the ID = 0
      It will return the ID as -1 if there is no front facing camera
    • Height As Int
    • Left As Int
    • MaximimDuration As Int [write only]
      Set the maximum duration of the recording
      Default value is 60000ms
      If maximum file size is reached before maximum duration then
      maximum file size will take preference and will stop the recording
    • MaximumDurationReachedToastMessage As String [write only]
      Set the toast message to be displayed when maximum duration has been reached
    • MaximumFileSize As Long [write only]
      Set the maximum file size for recording
      Default value is 5000000 bytes = 5MB
      If maximum duration is reached before maximum file size then
      maximum duration will take preference and will stop the recording
    • MaximumFileSizeReachedToastMessage As String [write only]
      Set the toast message to be displayed when maximum file size has been reached
    • ShowToastMessages As Boolean [write only]
      Show toast messages
    • StopCameraOnMaxSizeDuration As Boolean [write only]
      Stop the recording if maximum size or maximum duration has been reached
    • Tag As Object
    • Top As Int
    • VideoFolderName As String [write only]
      Set the folder name of where videos will be stored
      It starts from the root folder of your device
      If the folder does not exist it will be created automatically
      eg avc1.VideoFolderName = "MyVideoFolder/Videos"
      this will create a folder named MyVideoFolder in the root folder of your device
      It will then create a sub folder named Videos in folder MyVideoFolder
      Recorded videos will be stored in the folder named Videos
    • VideoName As String [write only]
      Set the name of your video recording file
      See also method AddTimeStampToFileName to add a timestamp to the file name
    • VideoQuality As Int [write only]
      Set the video quality based on one of the supported qualities
      See the call to getBackSupportedVideoQuality(0) and getFrontSupportedVideoQuality(1)
      If the device has a front camera only the call above need to be getFrontSupportedVideoQuality(0) i.e cameraID = 0
    • Visible As Boolean
    • Width As Int
    • ZoomWithSlider As Int [write only]
      Zoom In/Out with a slider
 

Attachments

  • b4aAndroidVideoCapture.zip
    39.3 KB · Views: 402
Last edited:

JordiCP

Expert
Licensed User
Longtime User
Hi,

Will try this very soon, it seems a piece of good and hard work!! :)

Do you know if there is any way in the original project to have, somehow, access to the preview events so that the user can modifiy the frame and give it back to the encoder? I mean, breaking the direct path from camera to encoder?
 

Prosg

Active Member
Licensed User
Longtime User
Here it is - cleaned out all the debugging messages and added help to all the public methods...

The library as it stands at present:

AndroidVideoCapture
Author:
Original project by: Andr.oid Eric, Adapted, modified, and wrapped by: Johan Schoeman
Version: 1
  • AndroidVideoCapture
    Events:
    • flash_toggled (flashOnOrOff As Boolean)
    • max_duration_reached (maxdurationreached As Boolean)
    • max_file_size_reached (maxsizereached As Boolean)
    • recording_time_remaining (remainingtime As String)
    Fields:
    • CAMERA_BACK As Int
      The ID of the back facing camera
      If the ID is -1 after initialization then the device does not support a back facing camera
      If the device has front and back cameras then the ID's will be BACK = 0 and FRONT = 1 after initialization
      If the device has a back camera only then the ID's will be BACK = 0 and FRONT = -1 after initialization
      If the device has a front camera only then the ID's will be BACK = -1 and FRONT = 0 after initialization
    • CAMERA_FRONT As Int
      The ID of the front facing camera
      If the ID is -1 after initialization then the device does not support a front facing camera
      If the device has front and back cameras then the ID's will be BACK = 0 and FRONT = 1 after initialization
      If the device has a back camera only then the ID's will be BACK = 0 and FRONT = -1 after initialization
      If the device has a front camera only then the ID's will be BACK = -1 and FRONT = 0 after initialization
    • QUALITY_1080P As Int
    • QUALITY_2160P As Int
    • QUALITY_480P As Int
    • QUALITY_720P As Int
    • QUALITY_CIF As Int
    • QUALITY_HIGH As Int
    • QUALITY_LOW As Int
    • QUALITY_QCIF As Int
    • QUALITY_QVGA As Int
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
      Initialize the videoWrapper class
      Eventname = name of events that this class will raise in B4A
      debugMessages = print debug messages to the log
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • 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)
    • ZoomIn
      Zoom In with increments of 1 at a time
    • ZoomOut
      Zoom Out with decrements of 1 at a time
    • getBackSupportedVideoQuality (cameraId As Int) As ArrayList
      Get a list of the video qualities that the back facing camera supports
      It returns a list of Strings with values such as
      QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF,
      QUALITY_QVGA, QUALITY_LOW, QUALITY_HIGH
      Use for eg avc1.VideoQuality = avc1.QUALITY_720P to set the quality
      that you want to use during recording
    • getFrontSupportedVideoQuality (cameraId As Int) As ArrayList
      Get a list of the video qualities that the front facing camera supports
      It returns a list of Strings with values such as
      QUALITY_1080P, QUALITY_720P, QUALITY_480P, QUALITY_CIF, QUALITY_QCIF,
      QUALITY_QVGA, QUALITY_LOW, QUALITY_HIGH
      Use for eg avc1.VideoQuality = avc1.QUALITY_720P to set the quality
      that you want to use during recording
    • hasCamera As Boolean
      Check if the device has a camera of any sort
    • hasFlash As Boolean
      Check if the device has a flash
    • releaseResources
      Release the camera and media recorder so that they can be
      used by other applications
    • setStartStopRecording
      Toggle stop/start of video recording
    • stopTimer
      it is used in Activity_Pause (UserClosed As Boolean)
      to ensure that the timer used inside the library
      is stopped in case it is still running when the user terminates the activity
    • toggleFlash
      Toggle the flash on/off should the camera in use have a flash
    Properties:
    • AddTimeStampToFileName As Boolean [write only]
      Add a time stamp to the file name
      The video will now be stored as YourVideoName_yyyyMMdd_HHmmss.MP4
    • BackFacingCamera As Int [read only]
      Get the ID of the back facing camera
      If the device has a front and back camera then the ID = 0
      If the device has a back facing camera only then the ID = 0
      It will return the ID as -1 if there is no back facing camera
    • Background As Drawable
    • CameraToUse As Int [write only]
      Set the camera to be use for recording
      For a device with front and back cameras ---> front = 1 and back = 0
      for a device with a front camera only ---> front = 0
      for a device with a back facing camera only ---> back = 0
      Use avc1.BackFacingCamera and avc1.FrontFacingCamera to get the camera ID's
    • Color As Int [write only]
    • Enabled As Boolean
    • FrontFacingCamera As Int [read only]
      Get the ID of the front facing camera
      If the device has a front and back camera then the ID = 1
      If the device has a front facing camera only then the ID = 0
      It will return the ID as -1 if there is no front facing camera
    • Height As Int
    • Left As Int
    • MaximimDuration As Int [write only]
      Set the maximum duration of the recording
      Default value is 60000ms
      If maximum file size is reached before maximum duration then
      maximum file size will take preference and will stop the recording
    • MaximumDurationReachedToastMessage As String [write only]
      Set the toast message to be displayed when maximum duration has been reached
    • MaximumFileSize As Long [write only]
      Set the maximum file size for recording
      Default value is 5000000 bytes = 5MB
      If maximum duration is reached before maximum file size then
      maximum duration will take preference and will stop the recording
    • MaximumFileSizeReachedToastMessage As String [write only]
      Set the toast message to be displayed when maximum file size has been reached
    • ShowToastMessages As Boolean [write only]
      Show toast messages
    • StopCameraOnMaxSizeDuration As Boolean [write only]
      Stop the recording if maximum size or maximum duration has been reached
    • Tag As Object
    • Top As Int
    • VideoFolderName As String [write only]
      Set the folder name of where videos will be stored
      It starts from the root folder of your device
      If the folder does not exist it will be created automatically
      eg avc1.VideoFolderName = "MyVideoFolder/Videos"
      this will create a folder named MyVideoFolder in the root folder of your device
      It will then create a sub folder named Videos in folder MyVideoFolder
      Recorded videos will be stored in the folder named Videos
    • VideoName As String [write only]
      Set the name of your video recording file
      See also method AddTimeStampToFileName to add a timestamp to the file name
    • VideoQuality As Int [write only]
      Set the video quality based on one of the supported qualities
      See the call to getBackSupportedVideoQuality(0) and getFrontSupportedVideoQuality(1)
      If the device has a front camera only the call above need to be getFrontSupportedVideoQuality(0) i.e cameraID = 0
    • Visible As Boolean
    • Width As Int
    • ZoomWithSlider As Int [write only]
      Zoom In/Out with a slider

hello

in post 48 the zip alllibrary have only

upload_2016-1-17_13-4-23.png


Did you forget all the library ?

Can your tell me if i have all your last library with number ?
upload_2016-1-17_13-10-18.png


ty
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User

Attachments

  • AllLibraryFiles.zip
    41.7 KB · Views: 398

Prosg

Active Member
Licensed User
Longtime User
i forget to ask u.... you know android have a time limit for record...

Do you think that with this library one day we could have unlimided video (when maxlimit = save and continue record ?)

regards
 

Johan Schoeman

Expert
Licensed User
Longtime User
i forget to ask u.... you know android have a time limit for record...

Do you think that with this library one day we could have unlimided video (when maxlimit = save and continue record ?)

regards
Not sure @Prosg. I have wrapped the project by Andr.oid Eric but not sure what the Android limits are. (when maxlimit = save and continue record ?) could probably be done but it will then be recorded in a new file with a new date/time stamp added to the file name...
 
Last edited:

Prosg

Active Member
Licensed User
Longtime User
ok :)

is it possible to record on portrait mode ? i change the designer but still landscape
 

Prosg

Active Member
Licensed User
Longtime User
Other question. Is it possible to have a preview before click Start ?

regards
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Johan. Great work as usual.
What you think, is it possible save this movie also in Streaming ( Look HERE )
 
Top