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):
7. Take note of the permissions added to the B4A manifest files (some are not required)
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:
Video recording started:
Zoomed In:
Flash switched on:
Sample Code:
The library as it stands at present:
AndroidVideoCapture
Author: Original project by: Andr.oid Eric, Adapted, modified, and wrapped by: Johan Schoeman
Version: 1
(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.b. use the "Toggle Flash" button
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:
Video recording started:
Zoomed In:
Flash switched on:
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 )
- 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
- 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
- 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
Last edited: