#Region Project Attributes
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private streamer As AudioStreamer
Private buffers As List
Private timer1 As Timer
Private recordingStart As Long
Private rp As RuntimePermissions
Public SourceDir As String
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private BtnStop As B4XView
Private BtnPlayback As B4XView
Private BtnPlay As B4XView
Private LbInfo As Label
Private LbClock As B4XView
Private Prec As B4XView
Private lblC As Label
'Requires Audio library
Private Pool As SoundPool
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission!", True)
'Return
End If
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_RECORD_AUDIO)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission!", True)
'Return
End If
Activity.LoadLayout("vrecorder2")
If FirstTime Then
streamer.Initialize("streamer", 44100, True, 16, streamer.VOLUME_MUSIC)
buffers.Initialize
timer1.Initialize("timer1", 1000)
End If
BtnPlayback.Enabled = False
Pool.Initialize(1)
End Sub
Sub streamer_RecordBuffer (Buffer() As Byte)
'collect the recording data
buffers.Add(Buffer)
End Sub
Sub Timer1_Tick
LbClock.Text = "Recording..."
End Sub
Sub Activity_Resume
End Sub
Sub BtnStop_Click
streamer.StopRecording
timer1.Enabled = False
BtnPlayback.Enabled = True
LbClock.Text = "STOPPED"
End Sub
Sub BtnPlayback_Click
''playback here
BtnStop.Enabled = True
BtnPlay.Enabled = False
streamer.StartPlaying
For Each b() As Byte In buffers
streamer.Write(b)
Next
PlayRecording
streamer.Write(Null)
LbClock.Text = "PLAYING BACK..."
End Sub
Sub streamer_PlaybackComplete
Log("PlaybackComplete")
BtnStop_Click
LbClock.Text = "FINISHED PLAYING"
Dim fd As InputDialog ' FileDialog
fd.Hint = "Save my recorded project audio from my supervisor or discussion?"
fd.HintColor = Colors.ARGB(255, 0, 0, 0)
Dim sf As Object = fd.ShowAsync("","Do you want to save or discard your recorded audio?", "OK","", "Cancel", Null, False)
Wait For (sf) Dialog_Result(Result As Int)
If Result = DialogResponse.POSITIVE Then
Log(fd.Input)
Dim file2 As String = fd.Input & ".wav"
MsgboxAsync("fd.input =" & file2, "test1")
ToastMessageShow("fd.input =" & file2, True)
SourceDir = rp.GetSafeDirDefaultExternal("myprojaudio")
File.Copy(SourceDir, "yourfilename.wav", File.DirInternal,fd.Input & ".wav")
If File.Exists(File.DirInternal,fd.Input & ".wav") Then
MsgboxAsync("fd.input =" & file2, "test2 exist")
'ToastMessageShow("fd.input =" & fd.Input, True)
End If
Starter.sql1.Initialize(File.DirInternal, "proj.db", False) 'DirInternal
Starter.sql1.ExecNonQuery2("INSERT INTO aulink(fname)VALUES(?)", Array As Object (file2))
ToastMessageShow("Your Audio saved as:" & file2, True)
Starter.sql1.Close
else if Result = DialogResponse.NEGATIVE Then
StartActivity(audioview)
End If
End Sub
Sub BtnRecording_Click
buffers.Clear
streamer.StartRecording
recordingStart = DateTime.Now
timer1.Enabled = True
Timer1_Tick
LbClock.Text = "RECORDING..."
LbClock.TextSize = "35"
BtnPlayback.Enabled = False
End Sub
Sub Activity_Click
End Sub
Sub PlayRecording
Dim ret As Int 'Used in call to Pool.Play. ret = 0 if error occurs
Dim PoolID As Int 'Identifies the Pool number when a sound file is loaded
File.MakeDir(rp.GetSafeDirDefaultExternal(""),"myprojaudio")
SourceDir = rp.GetSafeDirDefaultExternal("myprojaudio")
Dim SourceFileName As String = "yourfilename.wav" 'The file you wish to use
'Load the sound
PoolID = Pool.Load(SourceDir,SourceFileName) 'Loads the file and gets it's number in the pool.
MsgboxAsync("SourceDir =" & SourceDir, SourceFileName)
Sleep(100) 'Some delay required between pool loading and playback - I'm unsure why or how much?
'Play the sound
'ret = Pool.Play(PoolID,VolumeLeft,VolumeRight,Priority,Loop,Pitch)
ret = Pool.Play(PoolID,1,1,1,0,1)
End Sub