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


Java Clip.setFramePosition方法代码示例

本文整理汇总了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();
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:26,代码来源:MultiClip.java

示例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)
	{
		
	}
}
 
开发者ID:Meerkat007,项目名称:Java-Swing-Projects,代码行数:18,代码来源:a1.java

示例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); // 再生位置を最初に戻す
	}
}
 
开发者ID:PoochyEXE,项目名称:nullpomino,代码行数:9,代码来源:WaveEngine.java

示例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();
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:14,代码来源:Sounds.java

示例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();
}
 
开发者ID:tonikolaba,项目名称:BatBat-Game,代码行数:9,代码来源:JukeBox.java

示例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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:ClipOpenBug.java

示例7: stop

import javax.sound.sampled.Clip; //导入方法依赖的package包/类
public void stop()
{
  Clip myclip = getClip();
  if (myclip != null)
    {
      myclip.stop();
      myclip.setFramePosition(0);
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:10,代码来源:Applet.java

示例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);
	}
}
 
开发者ID:WorldGrower,项目名称:WorldGrower,代码行数:16,代码来源:Sound.java

示例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();
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:10,代码来源:Aurelizer.java

示例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);
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:10,代码来源:Aurelizer.java

示例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();		
}
 
开发者ID:captainsoft,项目名称:terminal-angel-disease,代码行数:10,代码来源:ClipSoundManager.java

示例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();
	}
}
 
开发者ID:PoochyEXE,项目名称:nullpomino,代码行数:17,代码来源:WaveEngine.java

示例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);
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:7,代码来源:Sounds.java

示例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.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:bug6251460.java

示例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();
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:7,代码来源:Aurelizer.java


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