package kkk; import java.io.File; import javax.media.Manager; import javax.media.Player; import javax.swing.JOptionPane; public class GunFireSoundEffect { private Player player; public void gunFireSound() { File file = new File("C:\\KKKFOLDER\\rShot.mp3"); try { player = Manager.createPlayer(file.toURL()); player.start(); // start player } catch (Exception e) { JOptionPane.showMessageDialog(null, "Invalid file or location", "Error loading file", JOptionPane.ERROR_MESSAGE); } } public static void main(String[] args) { new GunFireSoundEffect().gunFireSound(); } }
this code for a gun fire sound effect works perfectly fine.. im using it in the game that im creating .. where the enemy shoots. i put it in the loop where the gun fire animation happens. the problem is that every time the the gunFireSound() method is being called.. there is something poping out in my task bar everytime the sound effect is being generated... how can i resolve this one?
it seems like an mp3 player or a player is simultaneously being opened everytime i generate the sound.. i just need a sound effet.. thats all