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


Java Clip.close方法代码示例

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


在下文中一共展示了Clip.close方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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: destroy

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
 * Destroys the MultiClip and releases all resources.
 */
public void destroy() {
	if (clips.size() > 0) {
		for (Clip c : clips) {
			c.stop();
			c.flush();
			c.close();
		}
		extraClips -= clips.size() - 1;
		clips = new LinkedList<Clip>();
	}
	audioData = null;
	if (audioIn != null) {
		try {
			audioIn.close();
		} catch (IOException e) {
			explode(String.format("Could not close AudioInputStream for MultiClip %s.", name), e,
				DEFAULT_OPTIONS);
		}
	}
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:24,代码来源:MultiClip.java

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

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

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

示例7: doMixerClip

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private static void doMixerClip(Mixer mixer) throws Exception {
    boolean waitedEnough=false;
    try {
        DataLine.Info info = new DataLine.Info(Clip.class, format);
        Clip clip = (Clip) mixer.getLine(info);
        clip.open(format, soundData, 0, soundData.length);

        // sanity
        if (clip.getMicrosecondLength()/1000 < 9900) {
            throw new Exception("clip's microsecond length should be at least 9900000, but it is "+clip.getMicrosecondLength());
        }
        long start = System.currentTimeMillis();

        System.out.println(" ---------- start --------");
        clip.start();
        // give time to actually start it. ALSA implementation needs that...
        Thread.sleep(300);
        System.out.println("drain ... ");
        clip.drain();
        long elapsedTime = System.currentTimeMillis() - start;
        System.out.println("close ... ");
        clip.close();
        System.out.println("... done");
        System.out.println("Playback duration: "+elapsedTime+" milliseconds.");
        waitedEnough = elapsedTime >= ((clip.getMicrosecondLength() / 1000) - TOLERANCE_MS);
    } catch (Throwable t) {
            System.out.println("  - Caught exception. Not failed.");
            System.out.println("  - "+t.toString());
            return;
    }
    if (!waitedEnough) {
        throw new Exception("Drain did not wait long enough to play entire clip.");
    }
    successfulTests++;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:ClipDrain.java

示例8: doMixerClip

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
private static boolean doMixerClip(Mixer mixer, AudioFormat format) {
    if (mixer==null) return false;
    try {
        System.out.println("Trying mixer "+mixer+":");
            DataLine.Info info = new DataLine.Info(
                                      Clip.class,
                                      format,
                                      (int) samplerate);

            Clip clip = (Clip) mixer.getLine(info);
        System.out.println("  - got clip: "+clip);
        System.out.println("  - open with format "+format);
        clip.open(format, buffer, 0, buffer.length);
        System.out.println("  - playing...");
        clip.start();
        System.out.println("  - waiting while it's active...");
        while (clip.isActive())
                Thread.sleep(100);
        System.out.println("  - waiting 100millis");
        Thread.sleep(100);
        System.out.println("  - drain1");
        clip.drain();
        System.out.println("  - drain2");
        clip.drain();
        System.out.println("  - stop");
        clip.stop();
        System.out.println("  - close");
        clip.close();
        System.out.println("  - closed");
    } catch (Throwable t) {
        System.out.println("  - Caught exception. Not failed.");
        System.out.println("  - "+t.toString());
        return false;
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:ChangingBuffer.java

示例9: 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 {
	final Clip clip = AudioSystem.getClip();
	clip.addLineListener(listener);
	clip.open(audioInputStream);
	try {
		clip.start();
		listener.waitUntilDone();
	} catch (final InterruptedException e) {
		e.printStackTrace();
	} finally {
		clip.close();
	}
	audioInputStream.close();
}
 
开发者ID:mars-sim,项目名称:mars-sim,代码行数:24,代码来源:TelegraphSound.java

示例10: ShutdownSound

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
@Override
public void ShutdownSound() {
	 // Wait till all pending sounds are finished.
	  boolean done = false;
	  int i;
	  

	  // FIXME (below).
	  //fprintf( stderr, "I_ShutdownSound: NOT finishing pending sounds\n");
	  //fflush( stderr );
	  
	  while ( !done)
	  {
	    for( i=0 ; i<numChannels && ((channels[i]==null)||(!channels[i].isActive())) ; i++);
	    // FIXME. No proper channel output.
	    if (i==numChannels)  done=true;
	  }
	  
	  for( i=0 ; i<numChannels; i++){
		  if (channels[i]!=null)
		channels[i].close();			
	  	}
	  
	  // Free up resources taken up by cached clips.
	  Collection<Clip> clips=this.cachedSounds.values();
	  for (Clip c:clips){
		  c.close();
	  }
	  
	  // Done.
	  return;
	
}
 
开发者ID:AXDOOMER,项目名称:mochadoom,代码行数:34,代码来源:ClipSFXModule.java

示例11: start

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public static long start() throws Exception {
    AudioFormat fmt = new AudioFormat(44100, 16, 2, true, false);
    if (addLen) {
        staticLen += (int) (staticLen / 5) + 1000;
    } else {
        staticLen -= (int) (staticLen / 5) + 1000;
    }
    if (staticLen > 8 * 44100 * 4) {
        staticLen = 8 * 44100 * 4;
        addLen = !addLen;
    }
    if (staticLen < 1000) {
        staticLen = 1000;
        addLen = !addLen;
    }
    int len = staticLen;
    len -= (len % 4);
    byte[] fakedata = new byte[len];
    InputStream is = new ByteArrayInputStream(fakedata);
    AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                                         44100, 16, 2, 4, 44100, false);
    AudioInputStream ais = new AudioInputStream(is, format, fakedata.length
            / format.getFrameSize());

    out("    preparing to play back " + len + " bytes == " + bytes2Ms(len,
                                                                      format)
                + "ms audio...");

    DataLine.Info info = new DataLine.Info(Clip.class, ais.getFormat());
    clip = (Clip) AudioSystem.getLine(info);
    clip.addLineListener(new LineListener() {
        public void update(LineEvent e) {
            if (e.getType() == LineEvent.Type.STOP) {
                out("    calling close() from event dispatcher thread");
                ((Clip) e.getSource()).close();
            } else if (e.getType() == LineEvent.Type.CLOSE) {
            }
        }
    });

    out("    opening...");
    try {
        clip.open(ais);
    } catch (Throwable t) {
        t.printStackTrace();
        clip.close();
        clip = null;
    }
    ais.close();
    if (clip != null) {
        out("    starting...");
        clip.start();
    }
    return bytes2Ms(fakedata.length, format);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:56,代码来源:ClipLinuxCrash.java

示例12: play

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public static void play(Mixer mixer) {
    int res = 0;
    try {
        println("Getting clip from mixer...");
        source = (Clip) mixer.getLine(info);
        println("Opening clip...");
        source.open(audioFormat, audioData, 0, audioData.length);
        println("Starting clip...");
        source.loop(Clip.LOOP_CONTINUOUSLY);
        println("Now open your ears:");
        println("- if you hear a sine wave playing,");
        println("  listen carefully if you can hear clicks.");
        println("  If no, the bug is fixed.");
        println("- if you don't hear anything, it's possible");
        println("  that this mixer is not connected to an ");
        println("  amplifier, or that its volume is set to 0");
        key();
    } catch (IllegalArgumentException iae) {
        println("IllegalArgumentException: "+iae.getMessage());
        println("Sound device cannot handle this audio format.");
        println("ERROR: Test environment not correctly set up.");
        if (source!=null) {
            source.close();
            source = null;
        }
        return;
    } catch (LineUnavailableException lue) {
        println("LineUnavailableException: "+lue.getMessage());
        println("This is normal for some mixers.");
    } catch (Exception e) {
        println("Unexpected Exception: "+e.toString());
    }
    if (source != null) {
        println("Stopping...");
        source.stop();
        println("Closing...");
        source.close();
        println("Closed.");
        source = null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:ClickInPlay.java


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