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:

Prosg

Active Member
Licensed User
Longtime User
hello,

one of my beta tester have a bug with Samsung Galaxy Core

The error in the google play is :

B4X:
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at videowrapper.videoWrapper.setStartStopRecording(videoWrapper.java:295)
at com.fitnjob.prosg.mprendrevideo._btnstartend_click(mprendrevideo.java:527)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4808)
at android.view.View$PerformClick.run(View.java:19918)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsC+aller.run(ZygoteInit.java:1397)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)

Do u have any idea ?

regards
 

Johan Schoeman

Expert
Licensed User
Longtime User
hello,

one of my beta tester have a bug with Samsung Galaxy Core

The error in the google play is :

B4X:
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at videowrapper.videoWrapper.setStartStopRecording(videoWrapper.java:295)
at com.fitnjob.prosg.mprendrevideo._btnstartend_click(mprendrevideo.java:527)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4808)
at android.view.View$PerformClick.run(View.java:19918)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsC+aller.run(ZygoteInit.java:1397)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)

Do u have any idea ?

regards
This is where it fails in the library:
mediaRecorder.start();

Seems as if the media recorder was prepared but failed to start. Does your beta tester see a toast message being displayed when it fails?

B4X:
Toast.makeText(BA.applicationContext, "Fail in prepareMediaRecorder()!\n - Ended -", 1).show();
 

Prosg

Active Member
Licensed User
Longtime User
i'm going to ask him.

this msg toast.maketest is automatic i have nothing to do with it ?
 

Johan Schoeman

Expert
Licensed User
Longtime User
he have no toast message :(

how can i solve this ?

regards
Try with the attached library files. We need to know if he can at least see this toast message:
"Got to 1"

I have also increased the time for the media recorder to prepare itself from 2 seconds to 3 seconds.
 

Attachments

  • AndroidVideoCaptureLibFilesV1_01.zip
    15.8 KB · Views: 259

Prosg

Active Member
Licensed User
Longtime User
my friend give me the phone, i had test whitout your zip and here is the debugger error


B4X:
mprendrevideo_btnstartend_click (B4A line: 120)
avc1.setStartStopRecording
java.lang.RuntimeException: start failed.
    at android.media.MediaRecorder.start(Native Method)
    at videowrapper.videoWrapper.setStartStopRecording(videoWrapper.java:295)
    at com.fitnjob.prosg.mprendrevideo._btnstartend_click(mprendrevideo.java:665)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:4808)
    at android.view.View$PerformClick.run(View.java:19918)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5536)
    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:1397)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)

i test with the zip
 

Johan Schoeman

Expert
Licensed User
Longtime User
my friend give me the phone, i had test whitout your zip and here is the debugger error


B4X:
mprendrevideo_btnstartend_click (B4A line: 120)
avc1.setStartStopRecording
java.lang.RuntimeException: start failed.
    at android.media.MediaRecorder.start(Native Method)
    at videowrapper.videoWrapper.setStartStopRecording(videoWrapper.java:295)
    at com.fitnjob.prosg.mprendrevideo._btnstartend_click(mprendrevideo.java:665)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:4808)
    at android.view.View$PerformClick.run(View.java:19918)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5536)
    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:1397)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)

i test with the zip
I don't have a similar device to test it on. I suggest you take the Java code in post #26 and modify/amend it to work for the device that you are having problems with.
 

Prosg

Active Member
Licensed User
Longtime User
bug and i see "Go to 1"

what i have to do ?

'im going to test #26
 

mvpmedia

Member
Licensed User
Longtime User
Are you taking requests?

I need realtime preview and portrait switchability. PLEEEEEEEEASE.
 

mvpmedia

Member
Licensed User
Longtime User
I've spent the last 48 hours trying to figure out your java code with my limited knowledge. it appears your java code is missing back/front camera code. i've tried using the simple library compiler tool exactly the way you posted it and it doesnt have the camera switching capability. can you post your latest code, or help me be able to switch to portrait. Also a realtime preview would be awesome.
 

Johan Schoeman

Expert
Licensed User
Longtime User
I've spent the last 48 hours trying to figure out your java code with my limited knowledge. it appears your java code is missing back/front camera code. i've tried using the simple library compiler tool exactly the way you posted it and it doesnt have the camera switching capability. can you post your latest code, or help me be able to switch to portrait. Also a realtime preview would be awesome.
Here is the Java code.
 

Attachments

  • TheJavaCode.zip
    8.9 KB · Views: 237

mvpmedia

Member
Licensed User
Longtime User
videoWrapper.java:789: error: cannot find symbol
if (ba.applicationContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
^
symbol: variable FEATURE_CAMERA_ANY
location: class PackageManager
Note: C:\MyCameraSurfaceView.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

any hints????
 

mvpmedia

Member
Licensed User
Longtime User
is there any way you could just attach a lib that has orientation set at 90 degrees for me, or have it set during init? i can't seem to make this work on my end. :( I've even trying decompiling and editing the bytecode but nothing works. I've been up for almost 2 days now.
 

Johan Schoeman

Expert
Licensed User
Longtime User
is there any way you could just attach a lib that has orientation set at 90 degrees for me, or have it set during init? i can't seem to make this work on my end. :( I've even trying decompiling and editing the bytecode but nothing works. I've been up for almost 2 days now.
Try with the attached library files.
 

Attachments

  • AndroidVideoCaptureLibFilesPortrait.zip
    15.8 KB · Views: 236

mvpmedia

Member
Licensed User
Longtime User
Thank You! I am much closer to being satisfied :D how much of a donation would you require to get live video preview into the lib? or should i just use cameraex or another lib to preview?

I sent you a little something.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thank You! I am much closer to being satisfied :D how much of a donation would you require to get live video preview into the lib? or should i just use cameraex or another lib to preview?

I sent you a little something.
Thank you for that. I will see if I can amend the code to do a preview prior to starting a recording.
 
Top