B4A Library Video Recording Portrait

This is a warp that I have done for @mvpmedia. It is based on this Github project. Have amended the original code somewhat to add the following additional functionality:
1. Take snapshots too (the original project only records video)
2. Define your own images for the buttons to stop/start video recording, swop between back and front camera, and taking snapshots.
3. Define the folder where the videos and snapshots will be stored (starting from the root folder of your device)
4. Added the standard shutter sound when taking a snapshot.

I have "dropped" the APK here for whoever would like to test it.

1.png



2.png



B4A Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: VideoRecordPortrait
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource

'IMPORTANT!!!! YOU NEED TO SET THIS PATH CORRECTLY FOR YOUR OWN COMPUTER!!!!!!!!!!!!!!!!!!
'THE BELOW PATH IS THE PATH FOR MY COMPUTER
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
#Extends: android.support.v7.app.AppCompatActivity

#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 Button1 As Button
    Private Label1 As Label
    Dim mycam As VideoRecordPortrait
  
    Dim videostartimage As Bitmap
    Dim videostopimage As Bitmap  
    Dim switchcameraimage As Bitmap
    Dim takepictureimage As Bitmap
  
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")
    mycam.Initialize("mycam")
    Label1.Visible = True
    Label1.Text = "Wrapped by Johan Schoeman"
    videostartimage.Initialize(File.DirAssets,"videostartbutton.png")
    videostopimage.Initialize(File.DirAssets,"videostopbutton.png")  
    switchcameraimage.Initialize(File.DirAssets,"switchcamerabutton.png")      
    takepictureimage.Initialize(File.DirAssets,"takepicturebutton.png")      
  
    mycam.MaximumDuration = 10000             'maximum recording time in milliseconds
    mycam.MaximumFileSize = 10000000          'maximum recording files size in bytes - in this case 10MB
  
    mycam.FolderName = "MikesVideoFolder"        'folder where video will be stored - starting from the root folder of your device
                                                 'if the folder does not exist it will be created
    mycam.VideoName = "MikesVideo"               'file name of the recorded video it will be stored as MikesVideo.mp4
                                                 'snapshots will also be stored in this folder
  
    mycam.TimerTextColor = Colors.Green          'text color of the video recording countdown timer
    mycam.ShowButtons = True                     'show or don't show the buttons
  
    'if you take out the following 4 lines it will revert to the default "button" images
    'The custom images are in the /Files folder of the B4A project
    'I have downloaded them, resized them to 64 x 64, changed their colors, and made their backgrounds transparent
    mycam.StartVideoImage = videostartimage       'the image (for the button) to be displayed for starting a video recording
    mycam.StopVideoImage = videostopimage         'the image (for the button) to be displayed to stop the video recording
    mycam.CameraSwitchImage = switchcameraimage   'the image (for the button) to be displayed to swop between the front and back cameras
    mycam.TakePictureImage = takepictureimage     'the image (for the button) to be displayed for taking snapshots
  
    mycam.ReturnToB4AafterPictureTaken = False    'either return to the B4A project or continue with the preview for another
                                                  'snapshot or to record a video
  

End Sub

Sub Activity_Resume
  
  
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
  
  mycam.StartCamera

End Sub

Sub mycam_new_video_captured
  
    Log("back in B4A and new VIDEO captured")
  
End Sub

Sub mycam_new_picture_captured
  
    Log("back in B4A and new PICTURE captured")
  
End Sub
 
Last edited:

gregchao

Member
Licensed User
Longtime User
I don't understand how to use the code based on the apk. Don't you need to have a library installed?
 

Johan Schoeman

Expert
Licensed User
Longtime User
I don't understand how to use the code based on the apk. Don't you need to have a library installed?
Download the APK, connect your device to your PC/laptop, and send the APK to your device. Then look for the APK on your device (it should be in the /Files folder of your device). Click on it - it will ask you to install the app.
 

gregchao

Member
Licensed User
Longtime User
I understand. I did it and the app works well. I would like to incorporate it in an app of my own but of course, I cannot.

Right now, I am using VideoRecordApp but it is very dependent on the default video recorders hosted on each particular phone and I discovered that some of the camera apps will not save correctly when using the command videoRecorder.Record2(File.DirInternal, "1.mp4", 60) (as an example.) After three tries, I found one that works called CameraMX. This is very undesirable.

Your approach has the advantage of being portrait and embedded. I read the version that you did in landscape and I liked it but of course, I would like a portrait version. You seem to indicate in the post that that version was only meant for landscape applications.

I am willing to donate if you could help me.
 

Johan Schoeman

Expert
Licensed User
Longtime User
I understand. I did it and the app works well. I would like to incorporate it in an app of my own but of course, I cannot.

Right now, I am using VideoRecordApp but it is very dependent on the default video recorders hosted on each particular phone and I discovered that some of the camera apps will not save correctly when using the command videoRecorder.Record2(File.DirInternal, "1.mp4", 60) (as an example.) After three tries, I found one that works called CameraMX. This is very undesirable.

Your approach has the advantage of being portrait and embedded. I read the version that you did in landscape and I liked it but of course, I would like a portrait version. You seem to indicate in the post that that version was only meant for landscape applications.

I am willing to donate if you could help me.
See PM that I have sent you. Thanks for the donation!
 
Top