Android Question [Solved] CameraView - startCapturingVideo not displaying video.

victormedranop

Well-Known Member
Licensed User
Longtime User
hi I'm using this amazing library from @DonManfred. if I start
B4X:
Cam.start

I can see the video but when I use

B4X:
Try
        Cam.startCapturingVideo(File.DirInternal,"video.mp4")
    Catch
        Log(LastException)
    End Try

there no video or error. any recomendation ?

here my code, using b4xpages

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
   
    Dim logo As ImageView
    Dim empleado As Label
    Dim localidad As Label
   
    Dim labelc As Label
    Dim labell As Label
   
    Dim cliente As EditText
    Dim telefono As EditText
    Dim placa As EditText
   
    Dim grabar As Button
    Dim video As Button
    Dim panel As Panel
    Dim listview As ListView
    
    
     Dim sql1 As SQL
     Dim PanelCamm As Panel
    
    Dim Cam As CameraView
   
    dim labelvideo  as label
   
    Dim btnStart,btnStop,btnSnapshot As Button
    
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MenuPage")
   
    logo.Initialize("Logo")
    logo.SetBackgroundImage(LoadBitmapResize(File.DirAssets, "logo.png", 40%x, 20%y, True))
    logo.Gravity = Gravity.FILL
    Root.AddView(logo, 5%x,2%y,150dip, 75dip)
   
   
   
    empleado.Initialize("empleado")
    empleado.Text = "EMP: Victor Medrano"
    empleado.TextColor = Colors.LightGray
    empleado.Gravity = Gravity.RIGHT
    Root.AddView(empleado,50%x, 5%y,200dip,40dip)
   
    localidad.Initialize("localidad")
    localidad.Text = "LOC: Hotel  Embajador"
    localidad.TextColor = Colors.LightGray
    localidad.Gravity = Gravity.RIGHT
    Root.AddView(localidad,50%x, 8%y,200dip,40dip)
   
    labelc.Initialize("labelc")
    labelc.Text = "Datos del Cliente"
    labelc.TextColor = Colors.White
    Root.AddView(labelc, 10%x, 21%y, 150dip, 40dip)

    cliente.Initialize("cliente")
    Dim bg1 As ColorDrawable
    bg1.Initialize(Colors.White,10)
    cliente.Background = bg1
    cliente.Hint = "Nombre"
    cliente.HintColor = Colors.LightGray
    Root.AddView(cliente, 10%x, 25%y, 250dip, 40dip)
   
    telefono.Initialize("telefono")
    Dim bg2 As ColorDrawable
    bg2.Initialize(Colors.White,10)
    telefono.Background = bg2
    telefono.hint = "telefono"
    telefono.HintColor = Colors.LightGray
    Root.AddView(telefono, 60%x, 25%y, 150dip, 40dip)
   
    placa.Initialize("placa")
    Dim bg3 As ColorDrawable
    bg3.Initialize(Colors.White,10)
    placa.Background = bg3
    placa.hint = "placa"
    placa.HintColor = Colors.LightGray
    Root.AddView(placa, 10%x, 33%y, 100dip, 40dip)
   
    grabar.Initialize("grabar")
    grabar.Text = "GRABAR"
    grabar.TextColor = Colors.White
    Dim bg4 As ColorDrawable
    bg4.Initialize(Colors.Red, 10)
    grabar.Background = bg4
    Root.AddView(grabar, 60%x, 33%y, 150dip, 40dip)
   
    video.Initialize("video")
    video.Text = "VIDEO"
    video.TextColor = Colors.white
    Dim bg5 As ColorDrawable
    bg5.Initialize(Colors.blue, 10)
    video.Background = bg5
    Root.AddView(video, 39%x, 33%y, 100dip, 40dip)
   
    labelvideo.Initialize("labelvideo")
    labelvideo.Text = "."
    labelvideo.TextColor = Colors.White
    labelvideo.TextSize = 13
    Root.AddView(labelvideo,  70%x, 38%y, 100dip, 40dip)
   
    labell.Initialize("labell")
    labell.Text = "Listado de Vehiculos"
    labell.TextColor = Colors.White
    Root.AddView(labell, 10%x, 41%y, 150dip, 40dip)

    panel.Initialize("panel")
    Dim bg6 As ColorDrawable
    bg6.Initialize(Colors.white, 10)
    panel.Background = bg6
    Root.AddView(panel, 10%x, 45%y, 404dip, 401dip)
   
    listview.Initialize("listview")
   
    Dim Label1 As Label
    Label1 = listview.TwoLinesLayout.SecondLabel
    Label1.TextSize = 16
    Label1.TextColor = Colors.blue
   
    Dim Label2 As Label
    Label2 = listview.TwoLinesLayout.Label
    Label2.TextSize = 14
    Label2.TextColor = Colors.green
   
    panel.AddView(listview,0%x,0%y, 400dip,400dip)


    PanelCamm.Initialize("panelcam")
'    Dim bg As ColorDrawable
'    bg.Initialize(Colors.LightGray,0)
'    PanelCamm.Background = bg
   
    Cam.Initialize("record")
'    Dim bg2 As ColorDrawable
'    bg2.Initialize(Colors.Yellow,0)
'    Cam.Background = bg2
    PanelCamm.AddView(Cam,2%x, 1%y, 240dip, 240dip)
   
    btnStart.Initialize("start")
    btnStop.Initialize("Stop")
    btnSnapshot.Initialize("take")
   
    btnStart.Text = "start"
    btnStop.Text = "stop"
    btnSnapshot.Text = "close"
   
    PanelCamm.AddView(btnStart,3%x, 25%y, 65dip, 40dip)
    PanelCamm.AddView(btnStop,15%x, 25%y, 65dip, 40dip)
    PanelCamm.AddView(btnSnapshot,27%x, 25%y, 65dip, 40dip)
   
    Root.Addview(PanelCamm, 27%x, 60%y, 250dip,250dip)
   
    PanelCamm.Visible = False
   
    Try
        If File.Exists(File.DirInternal, "database.db") Then
            sql1.Initialize(File.DirInternal, "database.db",False )
        Else
            File.Copy(File.DirAssets,"database.db",File.DirInternal, "database.db")
            sql1.Initialize(File.DirInternal, "database.db",False )
        End If
    Catch
        Log(LastException)
    End Try
    '

End Sub


private Sub start_Click
   
    Log("start_Click")
   
    PanelCamm.Visible = True
    Cam.BringToFront
'    Cam.setSessionVideo
'    Cam.Flash = True
    Try
        Cam.startCapturingVideo(File.DirInternal,"video.mp4")
    Catch
        Log(LastException)
    End Try

End Sub


private Sub stop_Click
    Log("stop_Click")
    If Cam.Started Then
        Cam.stopCapturingVideo
    End If
End Sub


private Sub take_Click
    Log("take_Click")
    If Cam.Started Then
        Cam.stop
    End If
    PanelCamm.Visible = False
End Sub

private Sub video_Click
    Log("video_Click")
    PanelCamm.Visible = True
End Sub

Private Sub grabar_Click
   
   
    Try
        sql1.ExecNonQuery2("INSERT INTO data ( nombre, telefono, placa, video, localidad, horaentrada, horasalida, entregado) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)" , Array As Object("some text", 2))
    Catch
        Log(LastException)
        ToastMessageShow(LastException,True)
    End Try
   
   
    Dim label1 As Label
    label1 = listview.TwoLinesLayout.Label
    label1.TextSize = 16
    label1.TextColor = Colors.blue
   
    Dim label2 As Label
    label2 = listview.TwoLinesLayout.SecondLabel
    label2.TextSize = 14
    label2.TextColor = Colors.blue

    listview.AddTwoLines(cliente.text, telefono.text)
   
    RefreshListView
   
   
    cliente.Text = ""
    telefono.Text = ""
    placa.Text = ""
End Sub

Private Sub listview_ItemClick (Position As Int, Value As Object)
    Log("listview_ItemClick   "&  Value )
End Sub  



Sub RefreshListView
   
    listview.Clear
    Dim Cursor As Cursor
    Cursor = sql1.ExecQuery("Select  nombre, telefono, placa FROM data")
    For i = 0 To Cursor.RowCount - 1
        Cursor.Position = i
        Log(Cursor.GetString("nombre"))
        Log(Cursor.GetString("telefono"))
        Log(Cursor.GetString("placa"))
    Next
       
End Sub



Sub record_onCameraClosed()
    Log($"Cam_onCameraClosed()"$)
End Sub

Sub record_onCameraOpened(options As Object)
    Log($"Cam_onCameraOpened()"$)
End Sub

Sub record_onExposureCorrectionChanged(newValue As Float, bounds() As Float, fingers() As Object)
    Log($"Cam_onExposureCorrectionChanged(${newValue},${bounds},${fingers})"$)
End Sub

Sub record_onFocusEnd(success As Boolean, x As Int, y As Int)
    Log($"Cam_onFocusEnd(${success},${x},${y})"$)
End Sub

Sub record_onOrientationChanged(orientation As Int)
    Log($"Cam_onOrientationChanged(${orientation})"$)
End Sub

Sub record_onPictureTaken(jpeg() As Byte)
    Log($"Cam_onPictureTaken()"$)
    Cam.start
End Sub

Sub record_onVideoTaken(path As String, filename As String)
    Log($"Cam_onVideoTaken(${path},${filename})"$)
    Cam.start
End Sub

Sub record_onZoomChanged(newValue As Float, bounds() As Float, fingers() As Object)
    Log($"Cam_onZoomchanged(${newValue},${bounds},${fingers})"$)
End Sub


note the example works, the only difference i can see is i'm not using the designer.
 
Last edited:
Top