@@ -125,27 +125,31 @@ public class FileAndMicAudioDevice implements AudioDevice {
125
125
this .releaseAudioResources ();
126
126
return ;
127
127
}
128
+ try {
129
+ while (keepAliveRendererRunnable ) {
130
+ // Get 10ms of PCM data from the SDK. Audio data is written into the ByteBuffer provided.
131
+ AudioDevice .audioDeviceReadRenderData (renderingAudioDeviceContext , readByteBuffer );
128
132
129
- while (keepAliveRendererRunnable ) {
130
- // Get 10ms of PCM data from the SDK. Audio data is written into the ByteBuffer provided.
131
- AudioDevice .audioDeviceReadRenderData (renderingAudioDeviceContext , readByteBuffer );
132
-
133
- int bytesWritten = 0 ;
134
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
135
- bytesWritten = writeOnLollipop (audioTrack , readByteBuffer , readByteBuffer .capacity ());
136
- } else {
137
- bytesWritten = writePreLollipop (audioTrack , readByteBuffer , readByteBuffer .capacity ());
138
- }
139
- if (bytesWritten != readByteBuffer .capacity ()) {
140
- Log .e (TAG , "AudioTrack.write failed: " + bytesWritten );
141
- if (bytesWritten == AudioTrack .ERROR_INVALID_OPERATION ) {
142
- keepAliveRendererRunnable = false ;
143
- break ;
133
+ int bytesWritten = 0 ;
134
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
135
+ bytesWritten = writeOnLollipop (audioTrack , readByteBuffer , readByteBuffer .capacity ());
136
+ } else {
137
+ bytesWritten = writePreLollipop (audioTrack , readByteBuffer , readByteBuffer .capacity ());
138
+ }
139
+ if (bytesWritten != readByteBuffer .capacity ()) {
140
+ Log .e (TAG , "AudioTrack.write failed: " + bytesWritten );
141
+ if (bytesWritten == AudioTrack .ERROR_INVALID_OPERATION ) {
142
+ keepAliveRendererRunnable = false ;
143
+ break ;
144
+ }
144
145
}
146
+ // The byte buffer must be rewinded since byteBuffer.position() is increased at each
147
+ // call to AudioTrack.write(). If we don't do this, will fail the next AudioTrack.write().
148
+ readByteBuffer .rewind ();
145
149
}
146
- // The byte buffer must be rewinded since byteBuffer.position() is increased at each
147
- // call to AudioTrack.write(). If we don't do this, will fail the next AudioTrack.write().
148
- readByteBuffer . rewind ();
150
+ } catch ( IllegalStateException error ) {
151
+ error . printStackTrace ();
152
+ releaseAudioResources ();
149
153
}
150
154
};
151
155
0 commit comments