iOS Question How do I create a button function that record and playback video

davepamn

Active Member
Licensed User
Longtime User
How do I create a function that will record video for 15 seconds, play it back, and save it to the gallery?
 
Last edited:

davepamn

Active Member
Licensed User
Longtime User
I found a code sample for taking a video, but it did not have a time setting.

Also, the code did not show how to save the video to the gallery

B4X:
Sub Process_Globals

    Public App As Application

    Public NavControl As NavigationController

    PrivatePage1AsPage

    Private ImageView1 As ImageView

    Private cam As Camera

    Private btnChoosePicture As Button

    Private btnTakePicture As Button

    Private btnTakeVideo As Button

    Private vv As VideoView

End Sub



Private Sub Application_Start (Nav As NavigationController)

    NavControl = Nav

    Page1.Initialize("Page1")

    Page1.Title = "Page 1"

    NavControl.NavigationBarVisible = False

    Page1.RootPanel.Color = Colors.White

    Page1.RootPanel.LoadLayout("1")

    NavControl.ShowPage(Page1)

    cam.Initialize("cam", Page1)

   

    'disable unsupported features

    btnTakePicture.Enabled = cam.IsSupported

    btnTakeVideo.Enabled = cam.IsVideoSupported

    vv.Initialize("vv")

    Page1.RootPanel.AddView(vv.View, ImageView1.Left, ImageView1.Top, _

        ImageView1.Width, ImageView1.Height)

    vv.View.Visible = False

End Sub



Private Sub Page1_Resize(Width As Int, Height As Int)

    'resize the VideoView to the same size as the ImageView.

    vv.View.SetLayoutAnimated(0, 1, ImageView1.Left, ImageView1.Top, _

        ImageView1.Width, ImageView1.Height)

End Sub



Sub btnTakeVideo_Click

    cam.TakeVideo

End Sub



Sub btnTakePicture_Click

    cam.TakePicture

End Sub



Sub btnChoosePicture_Click

    cam.SelectFromSavedPhotos(Sender, cam.TYPE_ALL)

End Sub



Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)

    If Success Then

        If Image.IsInitialized Then

            vv.View.Visible = False

            ImageView1.Bitmap = Image

        Else

            vv.View.Visible = True

            vv.LoadVideo(VideoPath, "")

        EndIf

    EndIf

End Sub
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
This works, but I have to click start recording video and ok on the max time met.

Is there a way to press one button and record 15 seconds without any user interaction. Like pressing a button on a physical camera, aim and click.
 
Upvote 0
Top