Android Question videoRecorder didnt work at sdk 24.

dragonguy

Active Member
Licensed User
Longtime User
i use this code running on sdk 24 but totally cant record video, is it i miss something?
B4X:
Sub Process_Globals
  Dim audioRecorder As AudioRecordApp
  Dim videoRecorder As VideoRecordApp
End Sub

Sub Globals
  Dim vv As VideoView
End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
    audioRecorder.Initialize("audioRecorder")
    videoRecorder.Initialize("videoRecorder")
  End If
  vv.Initialize("vv")
  Activity.AddView(vv, 0, 0, 100%x, 100%y)
  Activity.AddMenuItem("Record Video", "RecordVideo")
  Activity.AddMenuItem("Record Audio", "RecordAudio")
  ToastMessageShow("Press on Menu button...", True)
End Sub

Sub RecordVideo_Click
  videoRecorder.Record(File.DirRootExternal, "1.mp4")
End Sub
Sub RecordAudio_Click
  audioRecorder.Record(File.DirRootExternal, "1.3gpp")
End Sub
Sub videoRecorder_RecordComplete (Success As Boolean)
  Log(Success)
  If Success Then
    vv.LoadVideo(File.DirRootExternal, "1.mp4")
    vv.Play
  End If
End Sub
Sub audioRecorder_RecordComplete (Success As Boolean)
  Log(Success)
  If Success Then
    vv.LoadVideo(File.DirRootExternal, "1.3gpp")
    vv.Play
  End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

i attach the small test project.
please help me.
 

Attachments

  • test.zip
    6.8 KB · Views: 218

DonManfred

Expert
Licensed User
Longtime User
Using api 24 you need to use the runtimepermissions library i guess
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
Yes, I try to save in dirrootexternal. I have try to add the permission but still can't make it work.
B4X:
AddManifestText(
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Yes, I try to save in dirrootexternal. I have try to add the permission but still can't make it work.
No, you are NOT folowing the new runtimepermission-system... You are trying to do it the old way.

This is an optional feature. It is only relevant if android:targetSdkVersion is set to 23 or above.
If the targetSdkVersion is lower than 23 then the standard permissions system will be used on all devices including Android 6+.


Follow this tutorial: https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
Yes, I have read the post but I can't find the info about the dirrootexternal, only got
B4X:
1. Use RuntimePermissions.GetSafeDirDefaultExternal("") instead of File.DirDefaultExternal. The parameter passed is an optional subfolder that will be created under the default folder.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)

B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
  If Permission = rp.PERMISSION_WRITE_EXTERNAL_STORAGE Then
        If Result Then
            Log("You NOW can write to File.DirRootExternal") ' or start your recording here...
             File.WriteString(File.DirRootExternal, "String.txt", _
        "This is some string" & CRLF & "and this is another one.")
        End If
  End If
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
With Api 23+ you need to request the permission when you first time want to write there....
Remember the answer!
You dont need to request again in another activity when you already got the permission (your remembered value)

Take in account that the user may revoke the permission at some time. You need to request again in this case.
 
Upvote 0
Top