当前位置: 首页>>代码示例>>Java>>正文


Java Clip.open方法代码示例

本文整理汇总了Java中javax.sound.sampled.Clip.open方法的典型用法代码示例。如果您正苦于以下问题:Java Clip.open方法的具体用法?Java Clip.open怎么用?Java Clip.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.sampled.Clip的用法示例。


在下文中一共展示了Clip.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: play

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
	 * This method allows to actually play the sound provided from the
	 * {@link #audioInputStream}
	 * 
	 * @throws LineUnavailableException
	 *             if the {@link Clip} object can't be created
	 * @throws IOException
	 *             if the audio file can't be find
	 */
	protected void play() throws LineUnavailableException, IOException {
//		Clip clip = AudioSystem.getClip();
		Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
		clip.addLineListener(listener);
		clip.open(audioInputStream);
		try {
			clip.start();
			listener.waitUntilDone();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			clip.close();
		}
		audioInputStream.close();
	}
 
开发者ID:thahn0720,项目名称:agui_framework,代码行数:25,代码来源:AchievementSound.java

示例2: run

import javax.sound.sampled.Clip; //导入方法依赖的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: test

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private static void test(final AudioFormat format, final byte[] data)
        throws Exception {
    final Line.Info info = new DataLine.Info(Clip.class, format);
    final Clip clip = (Clip) AudioSystem.getLine(info);

    go = new CountDownLatch(1);
    clip.addLineListener(event -> {
        if (event.getType().equals(LineEvent.Type.START)) {
            go.countDown();
        }
    });

    clip.open(format, data, 0, data.length);
    clip.start();
    go.await();
    while (clip.isRunning()) {
        // This loop should not hang
    }
    while (clip.isActive()) {
        // This loop should not hang
    }
    clip.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:IsRunningHang.java

示例4: playSound

import javax.sound.sampled.Clip; //导入方法依赖的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: loadSound

import javax.sound.sampled.Clip; //导入方法依赖的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

示例6: playButtonClickNormalSound

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/** Play the audio clip when regular button is clicked. */
public void playButtonClickNormalSound()
{
	try
	{
		String soundName = "regular_button_click_sound.wav";    
		AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(soundName).getAbsoluteFile());
		Clip clip = AudioSystem.getClip();
		clip.open(audioInputStream);
		clip.setFramePosition(0);
		clip.start();
	}
	catch (Exception e)
	{
		
	}
}
 
开发者ID:Meerkat007,项目名称:Java-Swing-Projects,代码行数:18,代码来源:a1.java

示例7: play

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private void play(String wavPath, float db) {
    if (!dnd && db > -40) {
        ClassLoader classLoader = getClass().getClassLoader();
        try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
            Clip clip = AudioSystem.getClip();
            clip.open(stream);
            if (db != 0.0) {
                FloatControl gainControl =
                        (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
                gainControl.setValue(db);
            }
            clip.start();
        } catch (Exception e) {
            logger.error("Cannot start playing wav file: ", e);
        }
    }
}
 
开发者ID:Exslims,项目名称:MercuryTrade,代码行数:18,代码来源:SoundNotifier.java

示例8: playSound

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
 * <strong><em>playSound</em></strong><br /><br />
 * 
 * &emsp;Plays a .wav audio file located in /res/audio/.<br />
 * &emsp;<em>E.g.</em> <sub>audio</sub><br /><br />
 * &emsp;File location would be: <sub>/res/audio/audio.wav</sub><br />
 * &emsp;and would be played automatically.
 * 
 * @param audio - File name.
 */
public void playSound(String audio){
	try{
	    AudioInputStream audioInputStream =
	        AudioSystem.getAudioInputStream(
	        	 getClass().getResource("/audio/"+audio+".wav"));
	    Clip clip = AudioSystem.getClip();
	    clip.open(audioInputStream);
	    clip.start();
	    clip.addLineListener(new LineListener() {
			
			@Override
			public void update(LineEvent arg0) {
				if(arg0.getFramePosition()==clip.getFrameLength()){
					clip.close();
				}
			}
		});
	    clips.put(audio, clip);
	}catch(Exception e){
		e.printStackTrace();
	}
}
 
开发者ID:JediBurrell,项目名称:neo,代码行数:33,代码来源:Audio.java

示例9: main

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public static void main(String[] av) {
    if (av.length == 0)
        main(defSounds);
    else for (String a : av) {
        System.out.println("Playing  " + a);
        try {
            URL snd = AudioPlay.class.getResource(a);
            if (snd == null) {
                System.err.println("Cannot getResource "  + a);
                continue;
            }
            AudioInputStream audioInputStream =
                AudioSystem.getAudioInputStream(snd);
            final Clip clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            clip.start();
        } catch (Exception e) {
            System.err.println(e);
        }
     }
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:22,代码来源:AudioPlay.java

示例10: play

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private void play()
{
   byte[] out = new byte[HEADER_SIZE + 2 * samples.length];
   for (int i = 0; i < HEADER_SIZE; i++)
   {
      out[i] = header[i];
   }
   for (int i = 0; i < samples.length; i++)
   {
      int value = samples[i];
      if (value < 0) { value = value + 65536; }
      out[HEADER_SIZE + 2 * i] = (byte)(value % 256);
      out[HEADER_SIZE + 2 * i + 1] = (byte)(value / 256);
   }

   try
   {
      Clip clip = AudioSystem.getClip();
      clip.open(AudioSystem.getAudioInputStream(new ByteArrayInputStream(out)));
      clip.start(); 
   }
   catch (Exception ex)
   {
      error(ex.getMessage());
   }
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:27,代码来源:SoundClip.java

示例11: putToDatabase

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
protected boolean putToDatabase(final Chunk chunk, final int resnum) {

    final InputStream aiffStream
            = new MemoryInputStream(chunk.getMemory(), 0,
                    chunk.getSize() + Chunk.CHUNK_HEADER_LENGTH);
    try {

        final AudioFileFormat aiffFormat
                = AudioSystem.getAudioFileFormat(aiffStream);
        final AudioInputStream stream = new AudioInputStream(aiffStream,
                aiffFormat.getFormat(), (long) chunk.getSize());
        final Clip clip = AudioSystem.getClip();
        clip.open(stream);
        sounds.put(resnum, new DefaultSoundEffect(clip));
        return true;

    } catch (Exception ex) {

        ex.printStackTrace();
    }
    return false;
}
 
开发者ID:wandora-team,项目名称:zmpp-wandora,代码行数:26,代码来源:BlorbSounds.java

示例12: run

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
@Override
public void run() {
	AudioInputStream audioInputStream;

	try {
		audioInputStream = AudioSystem.getAudioInputStream(clickUrl);

		DataLine.Info info = new DataLine.Info(Clip.class, audioInputStream.getFormat());
		Clip clip = (Clip) AudioSystem.getLine(info);
		if (clip.isRunning()) {
			clip.close();
		}
		clip.open(audioInputStream);
		clip.start();
	} catch (Exception e) {
		e.printStackTrace();
           Main.myErr(Arrays.toString(e.getStackTrace()).replace(",", "\n"));
	}
}
 
开发者ID:HermexTools,项目名称:client-legacy,代码行数:20,代码来源:Sound.java

示例13: PreloadedPlayback

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
 * Creates a new {@code PreloadedPlayback}. PreloadedPlayback objects will
 * always be created by their associated PreloadedAudio object.
 * <p>
 * IMPLEMENTATION NOTE: Originally, the fetching of a new {@code Line} was
 * done in the {@code run} method, however testing revealed that latency is
 * decreased if a {@code Line} is acquired ahead of time, here in the
 * constructor.
 * 
 * @param audio
 *            The {@code Audio} that created this {@code PreloadedPlayback}.
 * @param audioFormat
 *            Specifies the particular arrangement of audio data.
 * @param audioBytes
 *            Holds the audio data from which a {@code Clip} will be
 *            created.
 * @param instanceID
 *            The {@code instanceID} of this {@code PreloadedPlayback}.
 */
protected PreloadedPlayback(Audio audio, AudioFormat audioFormat,
		byte[] audioBytes, long instanceID) {
	super(audio, instanceID);
	DataLine.Info info = new DataLine.Info(Clip.class, audioFormat);
	try {
		clip = (Clip) AudioSystem.getLine(info);
		clip.open(audioFormat, audioBytes, 0, audioBytes.length);
		if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
			volCtrl = (FloatControl) clip
					.getControl(FloatControl.Type.MASTER_GAIN);
		} else {
			logger.warning("Master-Gain control is not supported."
					+ " Volume will be fixed at the default level.");
		}
	} catch (LineUnavailableException ex) {
		ex.printStackTrace();
	}
	clip.addLineListener(this);
}
 
开发者ID:cmholton,项目名称:QwickSound,代码行数:39,代码来源:PreloadedPlayback.java

示例14: playMainMusic

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public void playMainMusic() {
try {
	clip = (Clip)AudioSystem.getLine(new Line.Info(Clip.class));
       clip.open(AudioSystem.getAudioInputStream(new File("sounds/main.wav")));
       
       FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
       gainControl.setValue(-20.0f); // Muziek moet niet boven soundeffects uitkomen, dus 20dB zachter
       
       clip.start();
       clip.loop(Clip.LOOP_CONTINUOUSLY);
   }
   catch (Exception exc) {
       exc.printStackTrace(System.out);
   }
    }
 
开发者ID:niekBr,项目名称:Mario,代码行数:16,代码来源:Menu.java

示例15: playAudioFile

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private Clip playAudioFile(URL soundURL) throws Exception
{
	AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundURL);
	BufferedInputStream bufferedInputStream = new BufferedInputStream(audioInputStream);
    AudioFormat af = audioInputStream.getFormat();
    int size = (int) (af.getFrameSize() * audioInputStream.getFrameLength());
    byte[] audio = new byte[size];
    DataLine.Info info = new DataLine.Info(Clip.class, af, size);
    bufferedInputStream.read(audio, 0, size);
    Clip clip = (Clip) AudioSystem.getLine(info);
    clip.open(af, audio, 0, size); 
    clip.start();
    bufferedInputStream.close();
    return clip;        

}
 
开发者ID:langmo,项目名称:youscope,代码行数:17,代码来源:YouPongSounds.java


注:本文中的javax.sound.sampled.Clip.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。