comparison android-project/src/org/libsdl/app/SDLActivity.java @ 4996:8d7315668e35

Fixed audio buffer lifecycle and implemented audio shutdown
author Sam Lantinga <slouken@libsdl.org>
date Thu, 13 Jan 2011 12:32:55 -0800
parents 9f9bea41e88f
children a514bfe6952a
comparison
equal deleted inserted replaced
4995:9f9bea41e88f 4996:8d7315668e35
137 int result = mAudioTrack.write(buffer, i, buffer.length - i); 137 int result = mAudioTrack.write(buffer, i, buffer.length - i);
138 if (result > 0) { 138 if (result > 0) {
139 i += result; 139 i += result;
140 } else if (result == 0) { 140 } else if (result == 0) {
141 try { 141 try {
142 Thread.sleep(10); 142 Thread.sleep(1);
143 } catch(InterruptedException e) { 143 } catch(InterruptedException e) {
144 // Nom nom 144 // Nom nom
145 } 145 }
146 } else { 146 } else {
147 Log.w("SDL", "SDL audio: error return from write(short)"); 147 Log.w("SDL", "SDL audio: error return from write(short)");
155 int result = mAudioTrack.write(buffer, i, buffer.length - i); 155 int result = mAudioTrack.write(buffer, i, buffer.length - i);
156 if (result > 0) { 156 if (result > 0) {
157 i += result; 157 i += result;
158 } else if (result == 0) { 158 } else if (result == 0) {
159 try { 159 try {
160 Thread.sleep(10); 160 Thread.sleep(1);
161 } catch(InterruptedException e) { 161 } catch(InterruptedException e) {
162 // Nom nom 162 // Nom nom
163 } 163 }
164 } else { 164 } else {
165 Log.w("SDL", "SDL audio: error return from write(short)"); 165 Log.w("SDL", "SDL audio: error return from write(short)");
166 return; 166 return;
167 } 167 }
168 } 168 }
169 } 169 }
170 170
171 public static void audioQuit() {
172 if (mAudioThread != null) {
173 try {
174 mAudioThread.join();
175 } catch(Exception e) {
176 Log.v("SDL", "Problem stopping audio thread: " + e);
177 }
178 mAudioThread = null;
179
180 Log.v("SDL", "Finished waiting for audio thread");
181 }
182
183 if (mAudioTrack != null) {
184 mAudioTrack.stop();
185 mAudioTrack = null;
186 }
187 }
171 } 188 }
172 189
173 /** 190 /**
174 Simple nativeInit() runnable 191 Simple nativeInit() runnable
175 */ 192 */
231 // Send a quit message to the application 248 // Send a quit message to the application
232 SDLActivity.nativeQuit(); 249 SDLActivity.nativeQuit();
233 250
234 // Now wait for the SDL thread to quit 251 // Now wait for the SDL thread to quit
235 if (mSDLThread != null) { 252 if (mSDLThread != null) {
236 //synchronized (mSDLThread) { 253 try {
237 try { 254 mSDLThread.join();
238 mSDLThread.join(); 255 } catch(Exception e) {
239 } catch(Exception e) { 256 Log.v("SDL", "Problem stopping thread: " + e);
240 Log.v("SDL", "Problem stopping thread: " + e); 257 }
241 }
242 //}
243 mSDLThread = null; 258 mSDLThread = null;
244 259
245 //Log.v("SDL", "Finished waiting for SDL thread"); 260 //Log.v("SDL", "Finished waiting for SDL thread");
246 } 261 }
247 262