コード例 #1
1
ファイル: SoundManager.java プロジェクト: tmackgit/GameDev
  /** Creates an AudioInputStream from a sound from an input stream */
  public AudioInputStream getAudioInputStream(InputStream is) {

    try {
      if (!is.markSupported()) {
        is = new BufferedInputStream(is);
      }
      // open the source stream
      AudioInputStream source = AudioSystem.getAudioInputStream(is);

      // convert to playback format
      return AudioSystem.getAudioInputStream(playbackFormat, source);
    } catch (UnsupportedAudioFileException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    } catch (IllegalArgumentException ex) {
      ex.printStackTrace();
    }

    return null;
  }
コード例 #2
0
ファイル: SoundServer.java プロジェクト: gryffenferd/Tetris
 /** @param filename le lien vers le fichier song (URL ou absolute path) */
 public SoundServer(String filename) {
   try {
     AudioInputStream stream = AudioSystem.getAudioInputStream(new File(filename));
     format = stream.getFormat();
     samples = getSamples(stream);
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #3
0
  public WavEffect(String fileName) {
    URL url = getClass().getResource("/audios/" + fileName);
    try {
      clip = AudioSystem.getClip();
      AudioInputStream input = AudioSystem.getAudioInputStream(url);
      clip.open(input);

    } catch (LineUnavailableException e) {
      e.printStackTrace();
    } catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #4
0
 public static void Play() {
   try {
     // Open an audio input stream.
     File soundFile = new File("foo.wav");
     AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
     // Get a sound clip resource.
     Clip clip = AudioSystem.getClip();
     // Open audio clip and load samples from the audio input stream.
     clip.open(audioIn);
     clip.start();
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (LineUnavailableException e) {
     e.printStackTrace();
   }
 }
コード例 #5
0
ファイル: SoundEffect.java プロジェクト: nikoca/oving10
 // Constructor to construct each element of the enum with its own sound file.
 SoundEffect(String soundFileName) {
   try {
     // Use URL (instead of File) to read from disk and JAR.
     URL url = this.getClass().getClassLoader().getResource(soundFileName);
     // Set up an audio input stream piped from the sound file.
     AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
     // Get a clip resource.
     clip = AudioSystem.getClip();
     // Open audio clip and load samples from the audio input stream.
     clip.open(audioInputStream);
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (LineUnavailableException e) {
     e.printStackTrace();
   }
 }