Hello. In my MusicBoxPlayer application, the "SoundRecorder" function only works with "RAF.Size" values less than 400000. This happens without any error message. What should I change to be able to save larger files from "File.DirInternal" where they were saved, to external storage?
Sub BtnSave_Click:
Sub BtnSave_Click
Msgbox2Async("Do you really want to save this sound?", "Save this sound", "Yes", "", "No", Null, True)
Wait For Msgbox_Result (Result As Int)
If Result=DialogResponse.POSITIVE Then
mFileName = DateTime.GetYear(DateTime.Now) & "-" & DateTime.GetMonth(DateTime.Now) & "-" & DateTime.GetDayOfMonth(DateTime.Now)
mFileName = mFileName & "-" & DateTime.Gethour(DateTime.Now) & "h" & DateTime.GetMinute(DateTime.Now) & ".wav"
FileName = mFileName
Log("Save: " & FileName)
CopyFileToExternalStorage(File.DirInternal, FileName, Storage.root, "")
btnPlay.Visible=False
btnSave.Visible = False
Label1.Text = "Recording: " & FileName & " on your external storage"
Sleep(6000)
Label1.Text = "To check if this file has been saved," & CRLF & "return to the MusicBoxCenter" & CRLF & "and display the file list."
Sleep(6000)
Label1.Text = ""
End If
End Sub
RAF:
Sub StartWaveFile(Dir3 As String, FileName3 As String, SampleRate As Int, Mono As Boolean _
, BitsPerSample As Int) As OutputStream
File.Delete(Dir3, FileName3)
Dim raf As RandomAccessFile
raf.Initialize2(Dir3, FileName3, False, True)
raf.WriteBytes("RIFF".GetBytes("ASCII"), 0, 4, raf.CurrentPosition)
raf.CurrentPosition = 8 'skip 4 bytes for the size
raf.WriteBytes("WAVE".GetBytes("ASCII"),0, 4, raf.CurrentPosition)
raf.WriteBytes("fmt ".GetBytes("ASCII"),0, 4, raf.CurrentPosition)
raf.WriteInt(16, raf.CurrentPosition)
raf.WriteShort(1, raf.CurrentPosition)
Dim numberOfChannels As Int
If Mono Then numberOfChannels = 1 Else numberOfChannels = 2
raf.WriteShort(numberOfChannels, raf.CurrentPosition)
raf.WriteInt(SampleRate, raf.CurrentPosition)
raf.WriteInt(SampleRate * numberOfChannels * BitsPerSample / 8, raf.CurrentPosition)
raf.WriteShort(numberOfChannels * BitsPerSample / 8, raf.CurrentPosition)
raf.WriteShort(BitsPerSample, raf.CurrentPosition)
raf.WriteBytes("data".GetBytes("ASCII"),0, 4, raf.CurrentPosition)
raf.WriteInt(0, raf.CurrentPosition)
raf.Close
Return File.OpenOutput(Dir3, FileName3, True)
End Sub
Sub CloseWaveFile(Dir3 As String, FileName3 As String)
Dim raf As RandomAccessFile
raf.Initialize2(Dir3, FileName3, False, True)
raf.WriteInt(raf.Size - 8, 4)
raf.WriteInt(raf.Size - 44, 40)
Log("RAF Size: "& raf.Size)
raf.Close
End Sub
Sub BtnSR_Click:
Sub btnSR_Click
btnStop.Enabled = True
rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
xui.MsgboxAsync("No permission", "")
Return
Else
mFileName = DateTime.GetYear(DateTime.Now) & "-" & DateTime.GetMonth(DateTime.Now) & "-" & DateTime.GetDayOfMonth(DateTime.Now)
mFileName = mFileName & "-" & DateTime.Gethour(DateTime.Now) & "h" & DateTime.GetMinute(DateTime.Now) & ".wav"
buffers.Clear
Output = StartWaveFile(File.DirInternal, mFileName, mSampleRate, mMono, mBitRate)
Recording = True
streamer.StartRecording
recordingStart = DateTime.Now
timer1.Enabled = True
Timer1_Tick
btnPlay.Enabled = False
btnSR.Enabled = False
Log("SR: " & mFileName)
End If
End Sub
Last edited: