Android Open Source - linevslinerpg Audio Player






From Project

Back to project page linevslinerpg.

License

The source code is released under:

Apache License

If you think the Android project linevslinerpg listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jmpmain.lvslrpg;
/*from  www . ja  v  a 2s . c o  m*/
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

/**
 * Audio playing class. Loads and plays audio files.
 */
public class AudioPlayer {

  /** Program context. */
  public static Context context;

  /** Sound pool containing and playing audio files. */
  private static SoundPool soundPool;

  public static int city;
  public static int coin;
  public static int dead;
  public static int hit;
  public static int potion;
  public static int scroll;
  public static int teleport;

  /**
   * Initializes audio and sound player.
   * Must be called before AudioPlayer can be used.
   */
  public static void initSounds() {
       soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);

       city = soundPool.load(context, R.raw.city, 1);
       coin = soundPool.load(context, R.raw.coin, 1);
       dead = soundPool.load(context, R.raw.dead, 1);
       hit = soundPool.load(context, R.raw.hit, 1);
       potion = soundPool.load(context, R.raw.potion, 1);
       scroll = soundPool.load(context, R.raw.scroll, 1);
       teleport = soundPool.load(context, R.raw.teleport, 1);
  }

  public static void playSound(int id) {
    if(GameThread.SoundOn){
        AudioManager mgr = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
        float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
        float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);    
        float volume = streamVolumeCurrent / streamVolumeMax;
  
        //Play sound.
        soundPool.play(id, volume, volume, 1, 0, 1f);
    }
  }
}




Java Source Code List

com.jmpmain.lvslrpg.AudioPlayer.java
com.jmpmain.lvslrpg.GameSurface.java
com.jmpmain.lvslrpg.GameThread.java
com.jmpmain.lvslrpg.LineCanvas.java
com.jmpmain.lvslrpg.MainActivity.java
com.jmpmain.lvslrpg.MapGenerator.java
com.jmpmain.lvslrpg.Map.java
com.jmpmain.lvslrpg.OptionsAdapter.java
com.jmpmain.lvslrpg.entities.AILineEntity.java
com.jmpmain.lvslrpg.entities.Entity.java
com.jmpmain.lvslrpg.entities.Item.java
com.jmpmain.lvslrpg.entities.LineEntity.java
com.jmpmain.lvslrpg.entities.PlayerLineEntity.java
com.jmpmain.lvslrpg.particles.Blood.java
com.jmpmain.lvslrpg.particles.Bomb.java
com.jmpmain.lvslrpg.particles.Energy.java
com.jmpmain.lvslrpg.particles.Heal.java
com.jmpmain.lvslrpg.particles.ItemParticle.java
com.jmpmain.lvslrpg.particles.Particle.java
com.jmpmain.lvslrpg.particles.Smoke.java