本文整理汇总了Java中javax.sound.sampled.Clip.setFramePosition方法的典型用法代码示例。如果您正苦于以下问题:Java Clip.setFramePosition方法的具体用法?Java Clip.setFramePosition怎么用?Java Clip.setFramePosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.Clip
的用法示例。
在下文中一共展示了Clip.setFramePosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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)
{
}
}
示例3: update
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public void update(LineEvent event) {
// ストップか最後まで再生された場合
if(event.getType() == LineEvent.Type.STOP) {
Clip clip = (Clip) event.getSource();
clip.stop();
clip.setFramePosition(0); // 再生位置を最初に戻す
}
}
示例4: play
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public static void play(Type type)
{
Clip[] cliparr = clips.get(type);
Clip clip = cliparr[type.current];
if(clip.isActive())
{
clip.flush();
clip.stop();
}
clip.setFramePosition(0);
clip.start();
}
示例5: play
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public static void play(String s, int i) {
if(mute) return;
Clip c = clips.get(s);
if(c == null) return;
if(c.isRunning()) c.stop();
c.setFramePosition(i);
while(!c.isRunning()) c.start();
}
示例6: main
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
boolean res = true;
try {
AudioInputStream ais = new AudioInputStream(
new ByteArrayInputStream(new byte[2000]),
new AudioFormat(8000.0f, 8, 1, false, false), 2000); //
AudioFormat format = ais.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format,
((int) ais.getFrameLength()
* format
.getFrameSize()));
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open();
FloatControl rateControl = (FloatControl) clip.getControl(
FloatControl.Type.SAMPLE_RATE);
int c = 0;
while (c++ < 10) {
clip.stop();
clip.setFramePosition(0);
clip.start();
for (float frq = 22000; frq < 44100; frq = frq + 100) {
try {
Thread.currentThread().sleep(20);
} catch (Exception e) {
break;
}
rateControl.setValue(frq);
}
}
} catch (Exception ex) {
ex.printStackTrace();
res = ex.getMessage().indexOf(
"This method should not have been invoked!") < 0;
}
if (res) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
throw new Exception("Test failed");
}
}
示例7: stop
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public void stop()
{
Clip myclip = getClip();
if (myclip != null)
{
myclip.stop();
myclip.setFramePosition(0);
}
}
示例8: play
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public void play() {
try {
final Clip clipToPlay;
if (preLoadedClip != null) {
clipToPlay = preLoadedClip;
clipToPlay.setFramePosition(0);
} else {
clipToPlay = openClip(CLOSE_AFTER_PLAYING);
}
clipToPlay.start();
} catch (IOException | LineUnavailableException | UnsupportedAudioFileException e) {
throw new IllegalStateException(e);
}
}
示例9: enter
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public synchronized void enter(String eventName)
{
Clip clip = (Clip)this.clips.get(eventName);
if (clip.isActive()) {
clip.stop();
}
clip.setFramePosition(0);
clip.start();
}
示例10: enter_loop
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public synchronized void enter_loop(String eventName)
{
Clip clip = (Clip)this.clips.get(eventName);
if (clip.isActive()) {
clip.stop();
}
clip.setFramePosition(0);
clip.loop(-1);
}
示例11: playClip
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public void playClip(final Clip clip) {
if (clip == null) {
return;
}
clip.stop();
clip.flush();
clip.setFramePosition(0);
clip.start();
}
示例12: play
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
/**
* 再生
* @param name 登録名
*/
public void play(String name) {
Clip clip = clipMap.get(name);
if(clip != null) {
// 停止
clip.stop();
// 再生位置を最初に戻す
clip.setFramePosition(0);
// 再生
clip.start();
}
}
示例13: loop
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public static void loop(final Type type) {
Clip[] cliparr = clips.get(type);
Clip clip = cliparr[type.current];
clip.setFramePosition(0);
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
示例14: test
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
static protected void test()
throws LineUnavailableException, InterruptedException {
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip)AudioSystem.getLine(info);
final MutableBoolean clipStoppedEvent = new MutableBoolean(false);
clip.addLineListener(new LineListener() {
@Override
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
synchronized (clipStoppedEvent) {
clipStoppedEvent.value = true;
clipStoppedEvent.notifyAll();
}
}
}
});
clip.open(format, soundData, 0, soundData.length);
long lengthClip = clip.getMicrosecondLength() / 1000;
log("Clip length " + lengthClip + " ms");
log("Playing...");
for (int i=1; i<=LOOP_COUNT; i++) {
long startTime = currentTimeMillis();
log(" Loop " + i);
clip.start();
synchronized (clipStoppedEvent) {
while (!clipStoppedEvent.value) {
clipStoppedEvent.wait();
}
clipStoppedEvent.value = false;
}
long endTime = currentTimeMillis();
long lengthPlayed = endTime - startTime;
if (lengthClip > lengthPlayed + 20) {
log(" ERR: Looks like sound didn't play: played " + lengthPlayed + " ms instead " + lengthClip);
countErrors++;
} else {
log(" OK: played " + lengthPlayed + " ms");
}
clip.setFramePosition(0);
}
log("Played " + LOOP_COUNT + " times, " + countErrors + " errors detected.");
}
示例15: enter
import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public synchronized void enter(String eventName) {
Clip clip = (Clip)clips.get(eventName);
if (clip.isActive()) clip.stop();
clip.setFramePosition(0);
clip.start();
}