Java UnsupportedAudioFileException Example

说明

java unsupportedaudiofileexception示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Java

类/类型: UnsupportedAudioFileException

示例#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
文件: 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
文件: WavEffect.java项目: caosytrung/Game_RushGold

  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
文件: Soundplayer.java项目: msim0n/ACL_Projet_Decorator

 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
文件: 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();
   }
 }

展开阅读全文