Main repository of MikuMikuStudio
リビジョン | febc90c68ebfdc48e4336ec8f0bb8f20c2407f91 (tree) |
---|---|
日時 | 2013-05-14 00:56:29 |
作者 | iwgeric@gmail.com <iwgeric@gmai...> |
コミッター | iwgeric@gmail.com |
Android: Added methods for OpenAL Soft Audio Renderer to pause and resume audio when app is placed in the background
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10613 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -15,6 +15,7 @@ import android.widget.ImageView; | ||
15 | 15 | import android.widget.TextView; |
16 | 16 | import com.jme3.audio.AudioRenderer; |
17 | 17 | import com.jme3.audio.android.AndroidAudioRenderer; |
18 | +import com.jme3.audio.android.AndroidOpenALSoftAudioRenderer; | |
18 | 19 | import com.jme3.input.JoyInput; |
19 | 20 | import com.jme3.input.TouchInput; |
20 | 21 | import com.jme3.input.android.AndroidSensorJoyInput; |
@@ -486,6 +487,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt | ||
486 | 487 | AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; |
487 | 488 | renderer.resumeAll(); |
488 | 489 | } |
490 | + if (result instanceof AndroidOpenALSoftAudioRenderer) { | |
491 | + AndroidOpenALSoftAudioRenderer renderer = (AndroidOpenALSoftAudioRenderer) result; | |
492 | + renderer.resumeAll(); | |
493 | + } | |
489 | 494 | } |
490 | 495 | //resume the sensors (aka joysticks) |
491 | 496 | if (app.getContext() != null) { |
@@ -525,6 +530,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt | ||
525 | 530 | AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; |
526 | 531 | renderer.pauseAll(); |
527 | 532 | } |
533 | + if (result instanceof AndroidOpenALSoftAudioRenderer) { | |
534 | + AndroidOpenALSoftAudioRenderer renderer = (AndroidOpenALSoftAudioRenderer) result; | |
535 | + renderer.pauseAll(); | |
536 | + } | |
528 | 537 | } |
529 | 538 | //pause the sensors (aka joysticks) |
530 | 539 | if (app.getContext() != null) { |
@@ -1299,6 +1299,69 @@ public class AndroidOpenALSoftAudioRenderer implements AudioRenderer, Runnable { | ||
1299 | 1299 | } |
1300 | 1300 | } |
1301 | 1301 | |
1302 | + public void pauseAll() { | |
1303 | + checkDead(); | |
1304 | + synchronized (threadLock) { | |
1305 | + while (!threadLock.get()) { | |
1306 | + try { | |
1307 | + threadLock.wait(); | |
1308 | + } catch (InterruptedException ex) { | |
1309 | + } | |
1310 | + } | |
1311 | + if (audioDisabled) { | |
1312 | + return; | |
1313 | + } | |
1314 | + | |
1315 | + for (int i = 0; i < channels.length; i++) { | |
1316 | + AudioSource src = chanSrcs[i]; | |
1317 | + if (src == null) { | |
1318 | + continue; | |
1319 | + } | |
1320 | + | |
1321 | + if (src.getStatus() == Status.Playing) { | |
1322 | + assert src.getChannel() != -1; | |
1323 | + | |
1324 | + logger.log(Level.FINE, "Pausing Source: {0}", src.getChannel()); | |
1325 | + alSourcePause(channels[src.getChannel()]); | |
1326 | + checkError(true); | |
1327 | + src.setStatus(Status.Paused); | |
1328 | + } | |
1329 | + } | |
1330 | + | |
1331 | + } | |
1332 | + } | |
1333 | + | |
1334 | + public void resumeAll() { | |
1335 | + checkDead(); | |
1336 | + synchronized (threadLock) { | |
1337 | + while (!threadLock.get()) { | |
1338 | + try { | |
1339 | + threadLock.wait(); | |
1340 | + } catch (InterruptedException ex) { | |
1341 | + } | |
1342 | + } | |
1343 | + if (audioDisabled) { | |
1344 | + return; | |
1345 | + } | |
1346 | + | |
1347 | + for (int i = 0; i < channels.length; i++) { | |
1348 | + AudioSource src = chanSrcs[i]; | |
1349 | + if (src == null) { | |
1350 | + continue; | |
1351 | + } | |
1352 | + | |
1353 | + if (src.getStatus() == Status.Paused) { | |
1354 | + assert src.getChannel() != -1; | |
1355 | + | |
1356 | + logger.log(Level.FINE, "Playing/Resuming Source: {0}", src.getChannel()); | |
1357 | + alSourcePlay(channels[src.getChannel()]); | |
1358 | + checkError(true); | |
1359 | + src.setStatus(Status.Playing); | |
1360 | + } | |
1361 | + } | |
1362 | + } | |
1363 | + } | |
1364 | + | |
1302 | 1365 | private int checkError(boolean stopOnError) { |
1303 | 1366 | int errorCode = alGetError(); |
1304 | 1367 | String errorText = AL.GetALErrorMsg(errorCode); |