We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2001

Summary: Android. Audio not initialized when thread starts.
Product: SDL Reporter: Sylvain <sylvain.becker>
Component: *don't know*Assignee: Gabriel Jacobo <gabomdq>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: ARM   
OS: Android (All)   

Description Sylvain 2013-07-30 16:19:17 UTC
Hi,

Here's a bug I got with an android application. It's very rare (a few stack traces obtained from google play: 1 per 10k). but easily fixed / at least here's a workaround ...

The Audio seems not to be initialised when the run() method is called with AudioStartThread().

-------------------
java.lang.IllegalStateException: play() called on uninitialized AudioTrack.
at android.media.AudioTrack.play(AudioTrack.java:829)
at org.libsdl.app.SDLActivity$1.run(SDLActivity.java:419)
at java.lang.Thread.run(Thread.java:856)
--------------------

The static variable "mAudioTrack" could be initialised to null, by default.

And some "try/catch" block added when doing : 
try{
  if (mAudioTrack != null){
    mAudioTrack.play();
    nativeRunAudioThread();
  }
} catch(Exception e) {}

and also 
try{
  if (mAudioTrack != null){
    mAudioTrack.stop();
  }
} catch(Exception e) {}
Comment 1 Gabriel Jacobo 2013-07-31 09:10:35 UTC
I've added a detection for the case where the AudioTrack is not properly initialized: http://hg.libsdl.org/SDL/rev/463f78515a07

Note that this won't probably fix your problem right away, what you need to do is detect if there was a problem initializing the SDL Audio backend, and if that's the case disable audio (or use the dummy driver?)