Android Question audio recorder not work in background

alireza1238

Member
hi i create audio recorder android in background
This is how it works after install automatic rec and after 2min stop record and after save file start rec again...
if activity open worked
after close activity all audio file is empty

please help me to fix this problem

i use this method
B4X:
Sub time_name As String
    
    Dim now As Long
    Dim year,month,day,hour,minute,secound,finally As String

    DateTime.DateFormat = "dd MMM yyyy"
    DateTime.Date(DateTime.now)
    year = DateTime.GetYear(DateTime.Now)
    month = DateTime.GetMonth(DateTime.Now)
    day = DateTime.GetDayOfMonth(DateTime.Now)
    hour = DateTime.GetHour(DateTime.Now)
    minute = DateTime.GetMinute(DateTime.Now)
    secound = DateTime.GetSecond (DateTime.Now)
    finally = year&"_"&month&"_"&day&"_"&hour&"_"&minute&"_"&secound
    Return finally
    
End Sub

Sub check_folder
    If File.IsDirectory(File.DirDefaultExternal,"zip")=True Then

    Else
        File.MakeDir(File.DirDefaultExternal,"zip")
    End If
    
End Sub

Sub auto_recorder
    Dim filename As String = time_name
    ad.Initialize
    ad.AudioSource = ad.AS_MIC
    ad.OutputFormat = ad.OF_THREE_GPP
    ad.AudioEncoder = ad.AE_AMR_NB
    ad.setOutputFile(File.DirDefaultExternal , "mp.amr")
    ad.prepare
    ad.start()
    Sleep(30000)
    ad.stop
    zip.ABZipfile(File.DirDefaultExternal&"/" , "mp.amr" , File.DirDefaultExternal&"/zip/"&filename&".zip")
End Sub
 
Top