And in case of any error you just ignore it and then read the audio from the Database?
I tried your app, record something. When writing to the database i get an error.
I´m not ignoring it and search for the problem.
I connected to your Database and check the table.
You did define chat_app_local_movil.audio as BLOB; means you can store up to 65535 Bytes to it. My 1st test was more already.
I changed the BLOB to a MEDIUMBLOB (16777215 bytes) and record something more.
I also get a networkonmainthread exception so i used DisableStrictMode. This is not recommended but i leave it for now.
I changed the sql query to be parametrized and more easy readable.
The recording are now successfully written to the database and even the playback did work.
Sub Service_Start (StartingIntent As Intent)
DisableStrictMode
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
Sub Service_TaskRemoved
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Sub DisableStrictMode
Dim jo As JavaObject
jo.InitializeStatic("android.os.Build.VERSION")
If jo.GetField("SDK_INT") > 9 Then
Dim policy As JavaObject
policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
Dim sm As JavaObject
sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
End If
End Sub
Sub Connect As ResumableSub
mysql.InitializeAsync("mysql", driver, jdbcUrl, Username, password)
Wait For MySQL_Ready (Success As Boolean)
If Success = False Then
Log("Check unfiltered logs for JDBC errors.")
End If
Return Success
End Sub
Sub CloseConnection
mysql.Close
End Sub
Sub UPLOAD_audio As ResumableSub
Wait For (Connect) Complete (Success As Boolean)
If Success Then
Try
'------------------------------------------
Dim ser As B4XSerializator
Dim serialized() As Byte = ser.ConvertObjectToBytes(Main.buffers)
'------------------------------------------
mysql.ExecNonQuery2($"REPLACE INTO vamos_chat.chat_app_local_movil(`id`,`audio`) VALUES (?,?)"$, Array(1,serialized))
Catch
Log($"Error_${LastException}"$)
End Try
CloseConnection
End If
Return True
End Sub
Sub DONWLOAD_audio As ResumableSub
Wait For (Connect) Complete (Success As Boolean)
If Success Then
Try
Dim sf As Object = mysql.ExecQueryAsync("mysql","SELECT chat_app_local_movil.mensaje,chat_app_local_movil.audio FROM chat_app_local_movil;", Null)
Wait For (sf) mysql_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
If Success Then
Do While Crsr.NextRow
'Log($"list: ${Crsr.GetBlob("audio")}"$)
Dim ser As B4XSerializator
Dim newlist As List = ser.ConvertBytesToObject(Crsr.GetBlob("audio"))
Return newlist
Loop
Crsr.Close
End If
Catch
Success = False
Log(LastException)
End Try
CloseConnection
End If
Return Success
End Sub