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


Java Clip.start方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: start

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
 * Plays the clip with the specified volume.
 * @param volume the volume the play at
 * @param listener the line listener
 * @throws LineUnavailableException if a clip object is not available or
 *         if the line cannot be opened due to resource restrictions
 */
public void start(float volume, LineListener listener) throws LineUnavailableException {
	Clip clip = getClip();
	if (clip == null)
		return;

	// PulseAudio does not support Master Gain
	if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
		// set volume
		FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
		float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
		gainControl.setValue(dB);
	}

	if (listener != null)
		clip.addLineListener(listener);
	clip.setFramePosition(0);
	clip.start();
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:26,代码来源:MultiClip.java

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: playSirenSound

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private void playSirenSound() {
	try {
		File soundFile = new File(sirenFile);
		AudioInputStream soundIn = AudioSystem.getAudioInputStream(soundFile);
		AudioFormat format = soundIn.getFormat();
		DataLine.Info info = new DataLine.Info(Clip.class, format);
		clip = (Clip) AudioSystem.getLine(info);
		clip.addLineListener(new LineListener() {
			@Override
			public void update(LineEvent event) {
				if (event.getType() == LineEvent.Type.STOP) {
					soundOn = false;
				}
			}
		});
		clip.open(soundIn);
		clip.start();
		soundOn = true;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:23,代码来源:UI.java

示例11: 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

示例12: 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

示例13: 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

示例14: playClip

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public static void playClip(File clipFile) throws IOException, 
  UnsupportedAudioFileException, LineUnavailableException, InterruptedException {
  class AudioListener implements LineListener {
    private boolean done = false;
    @Override public synchronized void update(LineEvent event) {
      Type eventType = event.getType();
      if (eventType == Type.STOP || eventType == Type.CLOSE) {
        done = true;
        notifyAll();
      }
    }
    public synchronized void waitUntilDone() throws InterruptedException {
      while (!done) { wait(); }
    }
  }
  AudioListener listener = new AudioListener();
  AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(clipFile);
  try {
    Clip clip = AudioSystem.getClip();
    clip.addLineListener(listener);
    clip.open(audioInputStream);
    try {
      clip.start();
      listener.waitUntilDone();
    } finally {
      clip.close();
    }
  } finally {
    audioInputStream.close();
  }
}
 
开发者ID:Jahani,项目名称:EnchantedForest,代码行数:32,代码来源:Sound.java

示例15: playIt

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private void playIt(InputStream inputStream) throws IOException, UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IllegalArgumentException {
	AudioListener listener = new AudioListener();
	try {
		AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(inputStream));
		AudioFormat format = audioInputStream.getFormat();
		DataLine.Info info = new DataLine.Info(Clip.class, format);
		Clip clip = (Clip) AudioSystem.getLine(info);
		clip.addLineListener(listener);
		clip.open(audioInputStream);
		try {
			clip.start();
			listener.waitUntilDone();
		} finally {
			clip.close();
		}
	} finally {
		inputStream.close();
	}
}
 
开发者ID:GoldenGnu,项目名称:jwarframe,代码行数:20,代码来源:AudioTool.java


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