Avoids crash in AudioTrack when audio starts in background mode

TBR=noahric

Bug: NONE
Change-Id: Ie528b36cc03d53b15fbfd56a386309a8c3adce73
Reviewed-on: https://webrtc-review.googlesource.com/2681
Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#19927}
This commit is contained in:
henrika 2017-09-22 13:16:31 +02:00 committed by Commit Bot
parent 2c30120fac
commit c3d0da097c

View File

@ -120,12 +120,19 @@ public class WebRtcAudioTrack {
// This priming will avoid an immediate underrun, but is not required.
// TODO(henrika): initial tests have shown that priming is not required.
audioTrack.play();
assertTrue(audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING);
} catch (IllegalStateException e) {
reportWebRtcAudioTrackStartError("AudioTrack.play failed: " + e.getMessage());
releaseAudioResources();
return;
}
// We have seen reports that AudioTrack.play() can sometimes start in a
// paued mode (e.g. when application is in background mode).
// TODO(henrika): consider calling reportWebRtcAudioTrackStartError()
// and release audio resources here as well. For now, let the thread start
// and hope that the audio session can be restored later.
if (audioTrack.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) {
Logging.w(TAG, "AudioTrack failed to enter playing state.");
}
// Fixed size in bytes of each 10ms block of audio data that we ask for
// using callbacks to the native WebRTC client.