javax.sound.sampled.Clip.setMicrosecondPosition()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中javax.sound.sampled.Clip.setMicrosecondPosition()方法的一些代码示例,展示了Clip.setMicrosecondPosition()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clip.setMicrosecondPosition()方法的具体详情如下:
包路径:javax.sound.sampled.Clip
类名称:Clip
方法名:setMicrosecondPosition

Clip.setMicrosecondPosition介绍

暂无

代码示例

代码示例来源:origin: ddf/Minim

public void setMillisecondPosition(int pos)
{
  c.setMicrosecondPosition( pos * 1000 );
}

代码示例来源:origin: nroduit/Weasis

/** Skip to the specified position */
public void skip(int position) { // Called when user drags the slider
  if (position < 0 || position > audioLength) {
    return;
  }
  audioPosition = position;
  clip.setMicrosecondPosition(position * 1000L);
  progress.setValue(position); // in case skip( ) is called from outside
}

代码示例来源:origin: com.github.bloodshura/shurax-assets

@Override
public void setPosition(@Nonnull Duration duration) {
  clip.setMicrosecondPosition(TimeUnit.NANOSECONDS.toMicros(duration.toNanos()));
}

代码示例来源:origin: net.sf.gluebooster.java.booster/gb-basic

/**
 * Plays the clip from a given microseconds position.
 * This methods ends when the clip has been played up to the end.
 *  
 */
@Override
public void run() {
  clip.setMicrosecondPosition(microsecondsPosition);
  clip.start();
}

代码示例来源:origin: nroduit/Weasis

/** Stop playing the sound and reset the position to 0 */
public void reset() {
  stop();
  clip.setMicrosecondPosition(0);
  audioPosition = 0;
  progress.setValue(0);
}

代码示例来源:origin: stackoverflow.com

protected synchronized void play(Clip clip){

  try{            
    if(clip.isOpen()){
      System.out.println("clip is opened...");
      clip.start();
      clip.setMicrosecondPosition(0);     //like rewinding the clip
       try {Thread.sleep(10);}
       catch (Exception e) {}
    }
    System.out.println("shooting");
  }
  catch(Exception e){e.printStackTrace();}
}

代码示例来源:origin: stackoverflow.com

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(...);
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
...
// Play the sound in a separate thread.
private void playSound() {
  Runnable soundPlayer = new Runnable() {

    @Override
    public void run() {
      try {
        clip.setMicrosecondPosition(0);
        clip.start();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  };
  new Thread(soundPlayer).start();
}

代码示例来源:origin: stackoverflow.com

class SoundHandler

  Clip gunshot;
  Clip explosion;

  public SoundHandler()
  {
    gunshot = loadGunshot();
    explosion = loadExplosion();
  }

  private Clip loadGunshot()
  {
    // code to make and open a Clip
  }

  public void playGunshot()
  {
    gunshot.setMicrosecondPosition(0);
    gunshot.start();
  }

  // et cetera
}

代码示例来源:origin: stackoverflow.com

import java.io.IOException;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class SoundClipTest{

  public static void main(String[] args) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
    URL myURL= ClassLoader.getSystemResource("abesti.wav");
    AudioInputStream audio = AudioSystem.getAudioInputStream(myURL);
    Clip clip = AudioSystem.getClip();
    clip.open(audio);
    clip.setMicrosecondPosition(3000000);
    clip.start();
    try {
    Thread.sleep(2000); //in milliseconds
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
    clip.stop();
  }
}

代码示例来源:origin: ddf/Minim

public void update(LineEvent event)
  {
    if ( event.getType().equals( LineEvent.Type.STOP ) )
    {
      if ( playing && loopCount != 0 )
      {
        c.setMicrosecondPosition( 0 );
        c.start();
        if ( loopCount > 0 )
        {
          loopCount--;
        }
      }
      else
      {
        playing = false;
      }
    }
  }
} );

代码示例来源:origin: stackoverflow.com

public void run() {
  try {
    clip.setMicrosecondPosition(0);
    clip.start();
  } catch (Exception e) {

代码示例来源:origin: stackoverflow.com

int progress = slider.getValue();
  long time = (long) (length * (progress / 100d));
  clip.setMicrosecondPosition(time);
} finally {
  userUpdate = false;

代码示例来源:origin: UNIVALI-LITE/Portugol-Studio

public void inicia(boolean repetir)
{
  if (clip == null)
  {
    return;
  }
  if (clip.isRunning())
  {
    clip.stop();
  }            
  clip.setFramePosition(0);
  if(clipTime>0)
  {
    clip.setMicrosecondPosition(clipTime);
    clipTime=0;
    clip.start();
  }
  if (!repetir)
  {
    clip.loop(0);
  }
  else
  {
    clip.loop(Clip.LOOP_CONTINUOUSLY);
  }
}

相关文章