@Override public void shoot(int initX, int initY) { // TODO Auto-generated method stub this.x = initX; this.y = initY; System.out.println("Shoooting!"); // ** add this into your application code as appropriate // Open an input stream to the audio file. InputStream in = null; try { in = new FileInputStream(Filename); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Create an AudioStream object from the input stream. AudioStream as = null; try { as = new AudioStream(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Use the static class member "player" from class AudioPlayer to play // clip. AudioPlayer.player.start(as); // Similarly, to stop the audio. // AudioPlayer.player.stop(as); }
/* Demonstrates reading in an Image with the ImageIO class. Image is the superclass of BufferedImage. Returns null on i/o error. */ public Image loadImage(String filename) { BufferedImage image = null; try { image = ImageIO.read(new File(filename)); } catch (IOException ex) { ex.printStackTrace(); } return image; }
public AudioStream loadAudio(String filename) { AudioStream as = null; try { InputStream in = new FileInputStream(filename); as = new AudioStream(in); } catch (IOException ex) { ex.printStackTrace(); } return as; }
@SuppressWarnings("restriction") public LogoAnimator(Image image2) { animRun = true; // open the sound file as a Java input stream // create an audiostream from the inputstream audioStream = null; InputStream in = null; InputStream in2 = null; InputStream in3 = null; InputStream in4 = null; try { in = new FileInputStream("bombSound.wav"); in2 = new FileInputStream("bombSound.wav"); in3 = new FileInputStream("bombSound.wav"); in4 = new FileInputStream("roll.wav"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { audioStream = new AudioStream(in); audioStream2 = new AudioStream(in2); audioStream3 = new AudioStream(in3); audioStream4 = new AudioStream(in4); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // play the audio clip with the audioplayer class imageBackground = image2; setSize(getPreferredSize()); images = new ImageIcon[totalImages]; images2 = new ImageIcon[totalImages2]; images3 = new ImageIcon[totalImages3]; for (int i = 0; i < images.length; ++i) images[i] = new ImageIcon("alphabet" + (i + 1) + ".gif"); for (int i = 0; i < images2.length; ++i) images2[i] = new ImageIcon("alphabet" + (i + 1) + ".gif"); for (int i = 0; i < images3.length; ++i) images3[i] = new ImageIcon("alphabet" + (i + 1) + ".gif"); startAnimation(); }
public static void music(char gameResult) { AudioPlayer MGP = AudioPlayer.player; AudioStream BGM, BGM1; AudioData MD; ContinuousAudioDataStream loop = null; try { InputStream winAudio = new FileInputStream("Audio/winrevised.wav"); InputStream loseAudio = new FileInputStream("Audio/loserevised.wav"); BGM = new AudioStream(winAudio); BGM1 = new AudioStream(loseAudio); if (gameResult == 'w') AudioPlayer.player.start(BGM); else if (gameResult == 'l') AudioPlayer.player.start(BGM1); // MD = BGM.getData(); // loop = new ContinuousAudioDataStream(MD); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException error) { error.printStackTrace(); } MGP.start(loop); }