OSDN Git Service

AndroidSound#play/loop now returns -1 on failure, to match other backends
authormoly <tsweston@gmail.com>
Tue, 28 May 2013 17:22:34 +0000 (18:22 +0100)
committermoly <tsweston@gmail.com>
Tue, 28 May 2013 17:22:34 +0000 (18:22 +0100)
CHANGES
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSound.java
backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtSound.java
gdx/src/com/badlogic/gdx/audio/Sound.java

diff --git a/CHANGES b/CHANGES
index 71fc695..f08b82a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -38,6 +38,7 @@
 - ScrollBar#setForceOverscroll renamed to setForceScroll, as it affects more than just overscroll.
 - ArrayMap#addAll renamed to putAll to match the other maps.
 - Added ObjectSet and IntSet.
+- Sound#play and Sound#loop on Android now return -1 on failure, to match other backends.
 
 [0.9.8]
 - see http://www.badlogicgames.com/wordpress/?p=2791
index aa9c231..546c9bf 100644 (file)
@@ -48,6 +48,9 @@ final class AndroidSound implements Sound {
        public long play (float volume) {\r
                if (streamIds.size == 8) streamIds.pop();\r
                int streamId = soundPool.play(soundId, volume, volume, 1, 0, 1);\r
+               //standardise error code with other backends\r
+               if (streamId == 0)\r
+                       return -1;\r
                streamIds.add(streamId);\r
                return streamId;\r
        }\r
@@ -81,6 +84,9 @@ final class AndroidSound implements Sound {
        public long loop (float volume) {\r
                if (streamIds.size == 8) streamIds.pop();\r
                int streamId = soundPool.play(soundId, volume, volume, 1, -1, 1);\r
+               //standardise error code with other backends\r
+               if (streamId == 0)\r
+                       return -1;\r
                streamIds.add(streamId);\r
                return streamId;\r
        }\r
@@ -115,6 +121,9 @@ final class AndroidSound implements Sound {
                        leftVolume *= (1 - Math.abs(pan));\r
                }\r
                int streamId = soundPool.play(soundId, leftVolume, rightVolume, 1, 0, pitch);\r
+               //standardise error code with other backends\r
+               if (streamId == 0)\r
+                       return -1;\r
                streamIds.add(streamId);\r
                return streamId;\r
        }\r
@@ -130,6 +139,9 @@ final class AndroidSound implements Sound {
                        leftVolume *= (1 - Math.abs(pan));\r
                }\r
                int streamId = soundPool.play(soundId, leftVolume, rightVolume, 1, -1, pitch);\r
+               //standardise error code with other backends\r
+               if (streamId == 0)\r
+                       return -1;\r
                streamIds.add(streamId);\r
                return streamId;\r
        }\r
index 6a57f72..13bde21 100644 (file)
@@ -45,12 +45,12 @@ public class GwtSound implements Sound {
 \r
        @Override\r
        public long loop () {\r
-               return 0;\r
+               return -1;\r
        }\r
 \r
        @Override\r
        public long loop (float volume) {\r
-               return 0;\r
+               return -1;\r
        }\r
 \r
        @Override\r
index b8c3d5d..4108637 100644 (file)
@@ -37,29 +37,29 @@ import com.badlogic.gdx.utils.Disposable;
  * @author badlogicgames@gmail.com */\r
 public interface Sound extends Disposable {\r
        /** Plays the sound. If the sound is already playing, it will be played again, concurrently.\r
-        * @return the id of the sound instance. */\r
+        * @return the id of the sound instance if successful, or -1 on failure. */\r
        public long play ();\r
 \r
        /** Plays the sound. If the sound is already playing, it will be played again, concurrently.\r
         * @param volume the volume in the range [0,1]\r
-        * @return the id of the sound instance */\r
+        * @return the id of the sound instance if successful, or -1 on failure. */\r
        public long play (float volume);\r
 \r
        /** Plays the sound. If the sound is already playing, it will be played again, concurrently.\r
         * @param volume the volume in the range [0,1]\r
         * @param pitch the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0\r
         * @param pan panning in the range -1 (full right) to 1 (full left). 0 is center position.\r
-        * @return the id of the sound instance */\r
+        * @return the id of the sound instance if successful, or -1 on failure. */\r
        public long play (float volume, float pitch, float pan);\r
 \r
        /** Plays the sound, looping. If the sound is already playing, it will be played again, concurrently.\r
-        * @return the id of the sound instance */\r
+        * @return the id of the sound instance if successful, or -1 on failure. */\r
        public long loop ();\r
 \r
        /** Plays the sound, looping. If the sound is already playing, it will be played again, concurrently. You need to stop the sound\r
         * via a call to {@link #stop(long)} using the returned id.\r
         * @param volume the volume in the range [0, 1]\r
-        * @return the id of the sound instance */\r
+        * @return the id of the sound instance if successful, or -1 on failure. */\r
        public long loop (float volume);\r
 \r
        /** Plays the sound, looping. If the sound is already playing, it will be played again, concurrently. You need to stop the sound\r
@@ -67,7 +67,7 @@ public interface Sound extends Disposable {
         * @param volume the volume in the range [0,1]\r
         * @param pitch the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0\r
         * @param pan panning in the range -1 (full right) to 1 (full left). 0 is center position.\r
-        * @return the id of the sound instance */\r
+        * @return the id of the sound instance if successful, or -1 on failure. */\r
        public long loop (float volume, float pitch, float pan);\r
 \r
        /** Stops playing all instances of this sound. */\r