Android Question Tracking the moment when playback sound in the buffer has finished

Lakhtin_V

Active Member
Licensed User
Longtime User
Tracking the moment of completion of playback in the buffer.
I use the code to play a list consisting of a sequence of bytes. The entire audio fragment is played successfully. The problem is that the cycle sending the sequence of bytes to STREAM ends much faster than the playback of the entire audio recording ends. I hoped to paint the lines on the screen synchronously with each buffer while the sound is playing. But the cycle runs quickly, and the entire melody, consisting of elements transmitted by the cycle, sounds much longer. How to track the moment when each elementary fragment in the cycle has worked in online mode.

Play sound buffer:
    If General.lstFinish.Size>0 Then
        streamerP.Initialize("stream",  Starter.mSampleRate, Starter.mMono, Starter.mBitRate, streamerP.VOLUME_MUSIC)
        streamerP.StartPlaying
        i=0
        For Each b() As Byte In General.lstFinish
            s=i*shag
            scvS.ScrollPosition=s
            If i>0 Then scvS.Panel.GetView(i-1).Color=Colors.White
            scvS.Panel.GetView(i).Color=Colors.Green
            streamerP.Write(b)
            i=i+1
        Next
        streamerP.Write(Null) 'when this "message" will be processed, the player will stop.
    End If
 

emexes

Expert
Licensed User
Does using AudioStreamer.PlaybackComplete event to detect "the moment when each elementary fragment in the cycle has worked" cause audio clicks?

Maybe Erel's method of using a crystal ball clock might work:
Use a timer and add the next x seconds each time (plus a few milliseconds to compensate for inaccuracies).

Or make the buffer small enough to only hold (for example) 30 ms of audio, and check the return status of AudioStreamer.Write to pace your line painting or whatever it is that you need done (approximately, close enough) in synch with the audio.
 
Upvote 0

emexes

Expert
Licensed User
How large are the b() byte arrays in the list General.lstFinish? (in number of bytes, and number of audio samples)

Always the same? or varying, in which case: what are the smallest and largest?
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
Using a timer solved all the problems.
Does using AudioStreamer.PlaybackComplete event to detect "the moment when each elementary fragment in the cycle has worked" cause audio clicks?

Maybe Erel's method of using a crystal ball clock might work:


Or make the buffer small enough to only hold (for example) 30 ms of audio, and check the return status of AudioStreamer.Write to pace your line painting or whatever it is that you need done (approximately, close enough) in synch with the audio.
Using a timer solved all the problems.
 
Upvote 0
Top