Audirecorder 2.0

jfitchett56

Member
Licensed User
Longtime User
Hi guys. Had this working then somehow it stoped. It is not calling Sub AR_Recordcomplete. I tried manually stopping recorder (ar.stop) and auto using maxrecord value and neither call the recordcomplete sub. any ideas where I dropped the ball. (hope i understood the tags here)
B4X:
 'Service module 
Sub Process_Globals
     Type Message (Address As String, Body As String)
     Dim m As Message
    Dim AudioRecorder As AudioRecordApp
   Dim BufferSize As Int
   Dim SampleRate As Int
   Dim ChannelConfig As Int
   Dim AudioFormat As Int
   Dim AudioSource As Int
   Dim NoChnls,BitsPerSample,DataSize As Int
   
   Dim AR As AudioRecorder
     Dim StartTime As Long
   
   Dim OutFile As RandomAccessFile
   
   Dim current_record_fileName As String
   Dim Record As Thread
   Dim t1 As Timer
   Dim Continue As Boolean
   
 End Sub
 Sub Globals

 End Sub
 
 Sub Service_Create
    Dim pi As SmsInterceptor
    pi.Initialize2("sms",999)
End Sub
   
 Sub Service_Destroy
 End Sub
 
 Sub sms_MessageReceived (From As String, Body As String) As Boolean
 Dim msg As String
    Log("Got a msg")
   msg=Body.ToLowerCase
   If msg.contains("recordaudio") Then
      Log("recordaudio msg: "&Body)
       RecordAudio(30000)
      Return True
   Else 
      Return False
   End If
   
 End Sub
  
 Sub Service_Start(startingIntent As Intent)
 End Sub
 
 Sub RecordAudio(ms As Long)
 Dim now As Long
 Dim ms As Long
 Dim x As Long
     AR.Initialize
    AR.AudioSource = AR.AS_MIC
    AR.OutputFormat = AR.OF_THREE_GPP
    AR.AudioEncoder = AR.AE_AMR_NB
     DateTime.DateFormat = "yyMMddHHmmss" ' See this page regarding uppercase letters.
    current_record_fileName = DateTime.Date(DateTime.now)
    current_record_fileName = current_record_fileName & ".wav"
    AR.setOutputFile(File.DirDefaultExternal,current_record_fileName)
   'delete the file if it exists to avoid problems with Random access files
     If File.Exists(File.DirDefaultExternal,current_record_fileName) Then
      File.Delete(File.DirDefaultExternal,current_record_fileName)
    End If
    AR.MaxDuration = 30000
    AR.prepare()
    ms=3000000
    Log("Starting record")
    AR.start
    'For x = 1 To ms 
    'Next 
    'AR.stop    
 End Sub

 Sub AR_Recordcomplete
   Log("Record Complete")
   sendfile(current_record_fileName)
End Sub

Sub sendfile(filename As String)
'   smsint.filetosend = filename
'   CallSub(smsint,"sendthefile")
Log("Sending File")
   B4AServer.sendfile(File.DirDefaultExternal,filename)
End Sub
 

jfitchett56

Member
Licensed User
Longtime User
yes

Yes I found that strange too. I also thought it odd that the example defines
Dim AudioRecorder As AudioRecordApp
then AR as Audiorecorder. When I tried to define ar directly as AudiorecorderApp it did ask for parameter but then had many other errors.
 
Upvote 0

jfitchett56

Member
Licensed User
Longtime User
Got it working

I think I was mixing libraries. One is audiorecord and one is audiorecorder
one has no recordcomplete event. Still get them confused....
 
Upvote 0
Top