How to implement audio in a Java game? -


i want add audio java game, don't know how put in practice. i've read, java plays wav files, files big. i've read little jlayer, need soundpool in android, handle in game effects. know how it? i've build class it?

here code i've used in game while using jlayer:

public class mp3 {   public void play(final inputstream in) {      new thread() {         @override         public void run() {            try {               new player(in).play();            } catch (exception e) {               system.err.println(e.getmessage());            }         }      }.start();    }  }   private hashmap<string, url> soundmap = new hashmap<string, url>();  public void loadsounds() {       string[] filenames = {          "5_seconds_remaining.mp3",          "10_seconds_remaining.mp3",          "button_press_loud.mp3"       };       (string s : filenames) {          soundmap.put(s.substring(0, s.indexof('.')), getclass().getresource("sounds/" + s));       }    }  public void playsound(string name) {      try {          new mp3().play(new bufferedinputstream(soundmap.get(name).openstream()));      } catch (ioexception ex) {} } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -