From 1c92f500ebcedff6a618bc1c6766782acdec1bbc Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Thu, 19 Apr 2012 16:09:18 +0000 Subject: [PATCH] AndroidAudioRenderer : propperly set the looping value on media player git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9323 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../audio/android/AndroidAudioRenderer.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/engine/src/android/com/jme3/audio/android/AndroidAudioRenderer.java b/engine/src/android/com/jme3/audio/android/AndroidAudioRenderer.java index 8910ae9f4..662e74cc7 100644 --- a/engine/src/android/com/jme3/audio/android/AndroidAudioRenderer.java +++ b/engine/src/android/com/jme3/audio/android/AndroidAudioRenderer.java @@ -295,16 +295,19 @@ public class AndroidAudioRenderer implements AudioRenderer, @Override public void onCompletion(MediaPlayer mp) { - mp.seekTo(0); - mp.stop(); - // XXX: This has bad performance -> maybe change overall structure of - // mediaplayer in this audiorenderer? - for (AudioNode src : musicPlaying.keySet()) { - if (musicPlaying.get(src) == mp) { - src.setStatus(Status.Stopped); - break; - } + if (mp.isPlaying()) { + mp.seekTo(0); + mp.stop(); } + // XXX: This has bad performance -> maybe change overall structure of + // mediaplayer in this audiorenderer? + for (AudioNode src : musicPlaying.keySet()) { + if (musicPlaying.get(src) == mp) { + src.setStatus(Status.Stopped); + break; + } + } + } /** @@ -342,9 +345,15 @@ public class AndroidAudioRenderer implements AudioRenderer, if (channel == 0) { soundpoolStillLoading.put(audioData.getId(), src); } else { + if (src.getStatus() != Status.Stopped) { + soundPool.stop(channel); + src.setStatus(Status.Stopped); + } src.setChannel(channel); // receive a channel at the last setSourceParams(src); // playing at least + + } } catch (IOException e) { logger.log(Level.SEVERE, @@ -386,11 +395,11 @@ public class AndroidAudioRenderer implements AudioRenderer, mp = new MediaPlayer(); mp.setOnCompletionListener(this); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - } - + } + try { if (src.getStatus() == Status.Stopped) { - mp.reset(); + mp.reset(); AssetKey key = audioData.getAssetKey(); AssetFileDescriptor afd = assetManager.openFd(key.getName()); // assetKey.getName() @@ -402,7 +411,7 @@ public class AndroidAudioRenderer implements AudioRenderer, src.setStatus(Status.Playing); musicPlaying.put(src, mp); mp.start(); - }else{ + } else { mp.start(); } } catch (IllegalStateException e) { @@ -413,7 +422,7 @@ public class AndroidAudioRenderer implements AudioRenderer, } private void setSourceParams(AudioNode src, MediaPlayer mp) { - mp.setLooping(true); + mp.setLooping(src.isLooping()); mp.setVolume(src.getVolume(), src.getVolume()); //src.getDryFilter(); }