Code example for SoundPool

Methods: playsetVolumestop

0
        } 
 
        if(!shipForwardPlaying){
 
            shipForwardPlaying = true;
            return ShipForward.setStreamID( sfx.play(ShipForward.getSoundID(),
                    curVolume-(curVolume*balance), curVolume+(curVolume*balance), 0,  -1, 0) );
 
        } 
 
        else{ 
 
            sfx.setVolume( ShipForward.getStreamID(), Math.abs(curVolume-(curVolume*balance) ),  Math.abs(curVolume+(curVolume*balance) ) );
            return false; 
 
        } 
 
    } 
 
    /** 
     * Avoid the misconception: This method does not stop the ship from moving forward, but rather 
     * it stops the sound of it moving forward. 
     * 
     * @return A boolean representing whether or not the sound was stopped deliberately, as opposed 
     *         to encountering an already finished stream. 
     */ 
    public boolean stopShipForward(){ 
 
        if(shipForwardPlaying){
 
            sfx.stop(ShipForward.getStreamID());
            shipForwardPlaying = false;
            return true; 
 
        } 
 
        else return false; 
    } 
 
    /** 
     * When the ship strafes it does not need to make the ship-forward sound--merely the ship-strafe sound 
     * is required. Hence when called this method automatically stops the ship-forward sound if it was playing. 
     * 
     * @param balance       The left/right stereo balance with which you want to play the sound. 
     * @param percentage    The percentage of the current sfx volume the sound should be played at. 
     * @return A boolean of whether or not the sound was played successfully. 
     */ 
    public boolean playShipStrafe(float balance, float percentage){
 
        float curVolume = (float)Math.pow( sfxVol*percentage, sfxScaleFactor );
 
        if(shipForwardPlaying){
            stopShipForward(); 
        } 
 
        if(!shipStrafePlaying){
 
            return ShipStrafe.setStreamID( sfx.play(ShipStrafe.getSoundID(),
                    curVolume-(curVolume*balance), curVolume+(curVolume*balance), 0,  -1, 0) );
 
        } 
 
        else{ 
 
            sfx.setVolume( ShipStrafe.getStreamID(), curVolume-(curVolume*balance), curVolume+(curVolume*balance) );
            return false; 
 
        } 
 
    } 
 
    /** 
     * Avoid the misconception: This method does not stop the ship from strafing, but rather 
     * it stops the sound of it strafing. 
     * 
     * @return A boolean representing whether or not the sound was stopped deliberately, as opposed 
     *         to encountering an already finished stream. 
     */ 
    public boolean stopShipStrafe(){ 
 
        if(shipStrafePlaying){
 
            sfx.stop(ShipStrafe.getStreamID());
            shipStrafePlaying = false;
            return true; 
 
        }