Add some protection against double init of the Android audio backend
This commit is contained in:
parent
5a167e03cd
commit
29c4f05ed5
1 changed files with 26 additions and 22 deletions
|
@ -490,17 +490,19 @@ public class SDLActivity extends Activity {
|
|||
// latency already
|
||||
desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize);
|
||||
|
||||
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate,
|
||||
channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM);
|
||||
|
||||
// Instantiating AudioTrack can "succeed" without an exception and the track may still be invalid
|
||||
// Ref: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/media/java/android/media/AudioTrack.java
|
||||
// Ref: http://developer.android.com/reference/android/media/AudioTrack.html#getState()
|
||||
|
||||
if (mAudioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
|
||||
Log.e("SDL", "Failed during initialization of Audio Track");
|
||||
mAudioTrack = null;
|
||||
return -1;
|
||||
if (mAudioTrack == null) {
|
||||
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate,
|
||||
channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM);
|
||||
|
||||
// Instantiating AudioTrack can "succeed" without an exception and the track may still be invalid
|
||||
// Ref: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/media/java/android/media/AudioTrack.java
|
||||
// Ref: http://developer.android.com/reference/android/media/AudioTrack.html#getState()
|
||||
|
||||
if (mAudioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
|
||||
Log.e("SDL", "Failed during initialization of Audio Track");
|
||||
mAudioTrack = null;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
audioStartThread();
|
||||
|
@ -511,17 +513,19 @@ public class SDLActivity extends Activity {
|
|||
}
|
||||
|
||||
public static void audioStartThread() {
|
||||
mAudioThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAudioTrack.play();
|
||||
nativeRunAudioThread();
|
||||
}
|
||||
});
|
||||
|
||||
// I'd take REALTIME if I could get it!
|
||||
mAudioThread.setPriority(Thread.MAX_PRIORITY);
|
||||
mAudioThread.start();
|
||||
if (mAudioThread == null) {
|
||||
mAudioThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAudioTrack.play();
|
||||
nativeRunAudioThread();
|
||||
}
|
||||
});
|
||||
|
||||
// I'd take REALTIME if I could get it!
|
||||
mAudioThread.setPriority(Thread.MAX_PRIORITY);
|
||||
mAudioThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void audioWriteShortBuffer(short[] buffer) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue