當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioSystem.getClip方法代碼示例

本文整理匯總了Java中javax.sound.sampled.AudioSystem.getClip方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioSystem.getClip方法的具體用法?Java AudioSystem.getClip怎麽用?Java AudioSystem.getClip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.sound.sampled.AudioSystem的用法示例。


在下文中一共展示了AudioSystem.getClip方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: EZSound

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
 * Creates a new sound out of the given file. Must be a .wav file.
 * 
 * While this constructor is available for usage, it is highly recommended that you do not use this.
 * Instead call EZ.addSound() method which will perform additional background actions to bind the sound to the window.
 * 
 * @param file of the sound to load.
 * */
public EZSound(String file) {
  /*
  filename = file;
  sound = tryLoadSound(file);
  if (sound == null) {
    System.out.println("Error loading sound file");
    System.exit(1);
  }
  if (sound == null) {
    reloadClip();
  }
  */
  try {
    AudioInputStream ais = AudioSystem.getAudioInputStream(new File(file).getAbsoluteFile());
    sound = AudioSystem.getClip();
    sound.open(ais);
  }
  catch (Exception e) {
    e.printStackTrace();
    System.out.println("Error loading sound file, it may not exist or another program has a lock on it.");
    System.exit(1);
  }
}
 
開發者ID:gcalica,項目名稱:agar.io,代碼行數:32,代碼來源:EZ.java

示例2: run

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
 * The sound is load and play in a thread no slow down the engine.
 * */
@Override
public void run() {
    try {
        InputStream in = new BufferedInputStream(this.getClass().getResourceAsStream(this.filename + ".wav"));
        Clip clip = AudioSystem.getClip();

        clip.open(AudioSystem.getAudioInputStream(in));
        if (this.loop){
            clip.loop(Clip.LOOP_CONTINUOUSLY);
        }
        clip.start();
    }catch (Exception e){
        System.err.println(e);
    }

}
 
開發者ID:Exia-Aix-A2,項目名稱:Boulder-Dash,代碼行數:20,代碼來源:Sound.java

示例3: loadClip

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
private void loadClip() {
	try {
		clip = AudioSystem.getClip();
		
		InputStream in = getClass().getClassLoader().getResourceAsStream(filePath);
		BufferedInputStream bufferedIn = new BufferedInputStream(in);
		AudioInputStream audioIn = AudioSystem.getAudioInputStream(bufferedIn);
		
		clip.open(audioIn);
		
		
		volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
	} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
		e.printStackTrace();
		System.exit(-1);
	}
}
 
開發者ID:ProjectK47,項目名稱:Mafia,代碼行數:18,代碼來源:AudioClip.java

示例4: playSound

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
private synchronized void playSound(final String audioFileName) {
	if(isSoundEnabled) {
		try {
			Clip clip = AudioSystem.getClip();
			InputStream inputStream = MainWindow.class.getResourceAsStream(audioFileName);
			if(inputStream != null) {
				AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
				clip.open(audioInputStream);
				clip.start();
			}
			else {
				System.out.println("Input stream not valid");
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
開發者ID:cyberpirate92,項目名稱:snake-game,代碼行數:20,代碼來源:MainWindow.java

示例5: open

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
@Override
public void open() throws AudioException {

	try {
		
		this.audioInputStream = Audio.getAudioInputStream(this.resource);
		this.clip = AudioSystem.getClip();
		this.clip.open(this.audioInputStream);
		this.clip.addLineListener(event -> {
			
			if(event.getType().equals(LineEvent.Type.STOP) && this.clip.getMicrosecondPosition() >= this.clip.getMicrosecondLength()) {
				
				this.trigger(AudioEvent.Type.REACHED_END);
			}
		});
		this.controls = AbstractAudio.extractControls(this.clip, this.controls);
		this.open = true;
		this.trigger(AudioEvent.Type.OPENED);
		
	} catch(Exception exception) {
		
		throw new AudioException(exception);
	}
}
 
開發者ID:RalleYTN,項目名稱:SimpleAudio,代碼行數:25,代碼來源:BufferedAudio.java

示例6: loadSound

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
 * WAV files only
 * 
 * @param name
 *            Name to store sound as
 * @param file
 *            Sound file
 */
public static void loadSound(String name, String file) {
	try {
		System.out.print("Loading sound file: \"" + file + "\" into clip: \"" + name + "\", ");
		BufferedInputStream in = new BufferedInputStream(SoundPlayer.class.getResourceAsStream(file));
		AudioInputStream ain = AudioSystem.getAudioInputStream(in);

		Clip c = AudioSystem.getClip();
		c.open(ain);
		c.setLoopPoints(0, -1);
		clips.put(name, c);
		ain.close();
		in.close();
		System.out.println("Done.");
	} catch (Exception e) {
		System.out.println("Failed. (" + e.getMessage() + ")");
	}
}
 
開發者ID:Keabot-Studios,項目名稱:Caritemere,代碼行數:26,代碼來源:SoundPlayer.java

示例7: SoundPlayingThread

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
public SoundPlayingThread(ListedSong listedSong, ProgressBar progress) {
	this.listedSong = listedSong;
	this.audioFile = listedSong.file;
	this.progress = progress;
	
	if (audioFile != null) {
		try {
            AudioInputStream audioInputStream;
			if(audioFile.getName().endsWith(".ogg") || audioFile.getName().endsWith(".mp3")) {
				audioInputStream = createFromOgg(audioFile);
			}
			else { // wav
				audioInputStream = AudioSystem.getAudioInputStream(audioFile);
			}
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
開發者ID:lukas2005,項目名稱:Device-Mod-Apps,代碼行數:22,代碼來源:ApplicationMusicPlayer.java

示例8: playAudio

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
public void playAudio(int tempo, boolean flag) throws UnsupportedAudioFileException, LineUnavailableException, IOException, InterruptedException{
    Clip clip = AudioSystem.getClip();
    URL url = getClass().getResource("/audio/smb_die.wav");
    URL urlToHot = this.getClass().getResource("/audio/smb_die.wav");
    System.out.println(urlToHot);
    this.audio = Applet.newAudioClip(url);
    if(flag) audio.loop();
    else audio.stop();
    
}
 
開發者ID:knowrafa,項目名稱:lembredio,代碼行數:11,代碼來源:Audio.java

示例9: playSound

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
/**
 * Plays a sound
 * @param soundFile The sound in the form of a File
 */
public static void playSound(File soundFile)
    {
        Clip clip;
        try 
            {
                clip = AudioSystem.getClip();
                clip.open(AudioSystem.getAudioInputStream(soundFile));
                clip.start();
            } 
        catch (Exception e) {}
    }
 
開發者ID:AutonomousCarProject,項目名稱:AutonomousCar,代碼行數:16,代碼來源:MiscellaneousMethods.java

示例10: Sound

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
public Sound(String file){
	try {
		ais = AudioSystem.getAudioInputStream(new File(file));
		clip = AudioSystem.getClip();
		clip.open(ais);
	} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
		e.printStackTrace();
	}
}
 
開發者ID:vanyle,項目名稱:Explorium,代碼行數:10,代碼來源:Sound.java

示例11: load

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
public static void load(String s, String n) {
	if(clips.get(n) != null) return;
	Clip clip;
	try {			
		AudioInputStream ais =
			AudioSystem.getAudioInputStream(
				JukeBox.class.getResourceAsStream(s)
			);
		AudioFormat baseFormat = ais.getFormat();
		AudioFormat decodeFormat = new AudioFormat(
			AudioFormat.Encoding.PCM_SIGNED,
			baseFormat.getSampleRate(),
			16,
			baseFormat.getChannels(),
			baseFormat.getChannels() * 2,
			baseFormat.getSampleRate(),
			false
		);
		AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);
		clip = AudioSystem.getClip();
		clip.open(dais);
		clips.put(n, clip);
	}
	catch(Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:tonikolaba,項目名稱:BatBat-Game,代碼行數:28,代碼來源:JukeBox.java

示例12: loadClip

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
private void loadClip(File audioFile) {
	try {
		AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
		clip = AudioSystem.getClip();
		clip.open(audioStream);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:AitorB,項目名稱:POPBL_V,代碼行數:10,代碼來源:ClipPlayer.java

示例13: SFXClip

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
public SFXClip(String fileName)
{
    File file = new File(fileName);
    try
    {
        AudioInputStream stream = AudioSystem.getAudioInputStream(file);
        this.clip = AudioSystem.getClip();
        this.clip.open(stream);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}
 
開發者ID:Joshuagollaher,項目名稱:HawkEngine,代碼行數:15,代碼來源:SFXClip.java

示例14: jButton16ActionPerformed

import javax.sound.sampled.AudioSystem; //導入方法依賴的package包/類
private void jButton16ActionPerformed(
    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed

    System.out.print("\7"); //Вот это вот издает звук

    Clip clip = null;
    try {
        clip = AudioSystem.getClip();
    } catch (LineUnavailableException ex) {
        ex.printStackTrace();
    }
    byte[] buf = new byte[1024];
    for (int j = 0; j < buf.length; j++) {
        buf[j] = (byte) j;

    }
    AudioFormat af = new AudioFormat(
        11025f,
        8, // sample size in bits
        2, // channels
        true, // signed
        false // bigendian
    );

    try {
        byte[] b = buf;
        AudioInputStream ais = new AudioInputStream(new ByteArrayInputStream(b), af, 512);

        clip.open(ais);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:34,代碼來源:FTest.java


注:本文中的javax.sound.sampled.AudioSystem.getClip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。