当前位置: 首页>>代码示例>>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;未经允许,请勿转载。