Android Question streamer_RecordBuffer not seeing value of Global Variable.

Isa Paine

Member
Licensed User
Longtime User
I have 2 threads not see each other setting a global variable.


When tmrTemp_Tick fires it disables itself and calls stop recording.
stopRecording sets audio streamer.stopRecording and the Global IsRecording = False
The problem is, there is still data in the audio buffer so streamer_RecordBuffer executes, and thinks IsRecording is true, even though IsRecording was set false by stopRecording.

Why does streamer_RecordBuffer think IsRecording = true?
How can I IsRecording so all objects see the updated vale?

B4X:
Sub tmrTemp_Tick
    tmrTemp.Enabled = False   
    stopRecording   
End Sub

Sub stopRecording

    Dim dateString As String

    streamer.stopRecording

    IsRecording = False
   
    DoEvents
    DisplayResult
   
End Sub

Sub streamer_RecordBuffer (Buffer() As Byte)
    Dim tempString As String
    Dim temperature As Double
   
    temperature = AudioUtils.GetTemperature(Buffer)
    tempString = temperature
    tempString = tempString.SubString2(0,tempString.IndexOf(".") + 2)
    surveyTransaction.temperatureMeasured = tempString
   
    DoEvents
    If IsRecording Then
        DisplayProcessingPanel(PROCESSING)
    End If
   
End Sub
 

stevel05

Expert
Licensed User
Longtime User
Are they really running in two separate threads? The fact that you are doing Gui operations from the sub suggests not. In which case the subs will run sequentially. If the recording sub is busy, it is likely that the timer_tick sub execution is delayed until the recording sub has finished.
 
Upvote 0

Isa Paine

Member
Licensed User
Longtime User
Ok, but if that were the case IsRecording would be set to false and my
B4X:
DisplayResult
sub would be behaving differently.
I am thinking streamer_RecordBuffer is firing after tmrTemp_Tick because IsRecording is true.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You can either create a thread to run the recording code in and exit when needed using an interrupt, or check the time within the recording code sub and exit when necessary.
 
Upvote 0
Top