Android Question Save audio to blob, then again to file, cannot replay.

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,
I use audioRecorder to record a voice, save the output to file and replay with videoview. It works.
I save the file to a blob in the database, later save the blob to a file and try to replay this - does not work.
What can I do?
 

grafsoft

Well-Known Member
Licensed User
Longtime User
May I post it?

B4X:
Sub saveittodb (i As Int)
   Dim n,s As String
   n=addslashes(chosencontact)
   
   DateTime.dateformat="yyyy-MM-dd"
   s = "insert into voices values ('" & DateTime.date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) & "','" & n & "'," & i & ", ?)"
   Dim InputStream1 As InputStream
  InputStream1 = File.OpenInput(File.DirRootExternal, "temp.3gpp")
  Dim OutputStream1 As OutputStream
  OutputStream1.InitializeToBytesArray(1000000)
  File.Copy2(InputStream1, OutputStream1)
  Dim Buffer() As Byte 'declares an empty array
  Buffer = OutputStream1.ToBytesArray
   SQL1.BeginTransaction
  Try
     SQL1.ExecNonQuery2(s, Array As Object(Buffer))
      SQL1.TransactionSuccessful
  Catch
     Log(LastException.Message)
  End Try
  SQL1.EndTransaction
  
End Sub

It is more or less copied from your example. Now I get it from the table, save to file and try to play. When playing, I hear the first 1/2 second or so.

B4X:
Sub Bplay_Click
   Dim cr As Cursor   
   Dim s As String
   s="select avoice from voices where (aloc='" & addslashes(chosencontact) & "') and (adate='" & sounddate & "')"
   cr=SQL1.execquery (s)
   ' Dim i As Int
   ' i=cr.rowcount
   cr.Position = 0
  Dim Buffer() As Byte 'declare an empty byte array
  Buffer = cr.GetBlob("avoice")
  Dim InputStream1 As InputStream
  InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
   Dim OutputStream1 As OutputStream
  OutputStream1=File.Openoutput(File.DirRootExternal, "temp.3gpp",False)
   File.Copy2(InputStream1, OutputStream1)
   i=File.Size (File.DirRootExternal, "temp.3gpp")
   
   vv.Visible=True
  vv.LoadVideo(File.DirRootExternal, "temp.3gpp")
   vv.Play
   
End Sub
 
Upvote 0
Top