Android Question [solved] CamEx2 Problem with Video

DonManfred

Expert
Licensed User
I use CamEx2 (and Camera2 library).
The same code in another app does work. But in my new app it raises an Error.

Logger connected to: 988ad036525346515630
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
autoversion: 39.0, 39
compilation time: 11/15/2018 10:26:38
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
Main.UserLoggedin()
** Activity (main) Pause, UserClosed = false **
** Activity (capturevideo) Create, isFirst = true **
FULL
SetState(Open false, Busy false, Video true)
** Activity (capturevideo) Resume **
CaptureVideo.Activity_Resume
CaptureVideo_OpenCamera(false)
SetState(Open false, Busy false, Video true)
PrepareSurface)
SetState(Open false, Busy false, Video true)
camex2$ResumableSub_PrepareSurfaceForVideoresume (java line: 1210)
java.io.FileNotFoundException: temp-: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:512)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:255)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:136)
at android.media.MediaRecorder.prepare(MediaRecorder.java:1231)
at anywheresoftware.b4a.objects.Camera2.StartSession(Camera2.java:273)
at de.fbdn.videohelper.camex2$ResumableSub_PrepareSurfaceForVideo.resume(camex2.java:1210)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:185)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1736)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Linux.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:207)
at libcore.io.IoBridge.open(IoBridge.java:498)
... 16 more

Permission for write external storage is Requested using RuntimePermission and it is granted.

B4X:
    cam.Initialize(pnlCamera)
    Log(cam.SupportedHardwareLevel)
    buttons = Array(btnMode)
    SetState(False, False, VideoMode)

B4X:
Sub Activity_Resume
    Log("CaptureVideo.Activity_Resume")
    OpenCamera(frontCamera)
End Sub
Sub CheckAllFieldsValid
    Dim valid As Boolean = DialogKommentar.Text.Length > 0
    DetailsDialog.GetButton(DialogResponse.POSITIVE).Enabled = valid
End Sub
Sub DialogKommentar_TextChanged (alt As String, Neu As String)
    CheckAllFieldsValid
End Sub
Sub OpenCamera (front As Boolean)
    Log($"CaptureVideo.OpenCamera(${front})"$)
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
        Return
    End If
    rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
        Return
    End If
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission to external SDCard!", True)
        Return
    End If
    
    SetState(False, False, VideoMode)
    Wait For (cam.OpenCamera(front)) Complete (TaskIndex As Int)
    If TaskIndex > 0 Then
        MyTaskIndex = TaskIndex 'hold this index. It will be required in later calls.
        Wait For(PrepareSurface) Complete (Success As Boolean)
    End If
    Log("Start success: " & Success)
    SetState(Success, False, VideoMode)
    If Success = False Then
        ToastMessageShow("Failed to open camera", True)
    End If
    'Log(cam.ActiveArraySize)
    'Log(cam.PreviewSize)
    'Log(cam.CaptureSize)
End Sub

Sub PrepareSurface As ResumableSub
    Log($"PrepareSurface)"$)
    SetState(False, busystate, VideoMode)
    'sizes can be modified here
    If VideoMode Then
        cam.PreviewSize.Initialize(640, 480)
        'Using a temporary file to store the video.
        Wait For (cam.PrepareSurfaceForVideo(MyTaskIndex, VideoFileDir, "temp-" & VideoFileName)) Complete (Success As Boolean)
    Else
        cam.PreviewSize.Initialize(1920, 1080)
        Wait For (cam.PrepareSurface(MyTaskIndex)) Complete (Success As Boolean)
    End If
    If Success Then cam.StartPreview(MyTaskIndex, VideoMode)
    SetState(Success, busystate, VideoMode)
    Return Success
End Sub

Any hints are higly appreciated.
 

MarkusR

Well-Known Member
Licensed User
i can't follow this path
B4X:
, VideoFileDir, "temp-" & VideoFileName)
 
Upvote 0

DonManfred

Expert
Licensed User
i can't follow this path
:oops:
b4a can not follow too. I forgot to set two variables to the right values (they are set in the other app on a different place).

Thank you!

Now i run into another problem.
java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface!
but i´ll create a new Thread about this Issue.
 
Upvote 0
Top