Java中的更多高级音频控件 [英] More Advanced Audio Controls in Java

查看:74
本文介绍了Java中的更多高级音频控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.applet.AudioClip相比,我需要更多的声音播放控制.所提供的就是播放,循环播放和停止音频剪辑的功能.我想知道如何控制播放哪个扬声器,声音的音量,播放声音的哪个部分等.是否有人想分享任何经验或建议?

I need more control over playing sounds than java.applet.AudioClip provides. All that gives is the ability to play, loop-play, and stop an audio clip. I would like to know how to control on which speaker it plays, what the volume of the sound is, what part of the sound to play, etc. Does anyone have any experience or advice they would like to share?

我已经实现了javax.sound.以下是我的代码的非常精简版:

I have implemented javax.sound. The following is a VERY dumbed-down version of my code:

public class Clazz extends JFrame
{
  public java.net.URL alertSoundURL = getClass().getResource("/resources/beep.wav");
  javax.sound.sampled.Clip timeUp;

  public Clazz()
  {
    try
    {
      javax.sound.sampled.AudioInputStream audioIn = javax.sound.sampled.AudioSystem.getAudioInputStream(alertSoundURL);
      timeUp = javax.sound.sampled.AudioSystem.getClip();
      timeUp.open(audioIn);
      timeUp.setLoopPoints(0, 10000);
      timeUp.start();
      timeUp.stop();
    }
    catch (Throwable t)
    {
      //Tell user sound may not work
    }
  }

  private void setOffAlarm()
  {
    alarmDialog.setSize(alarmDialog.getPreferredSize());
    FrameAction.center(alarmDialog);
    alarmDialog.setVisible(true);
    timeUp.loop(timeUp.LOOP_CONTINUOUSLY);
    newDay = false;
  }
}

我的问题是timeUp.loop(timeUp.LOOP_CONTINUOUSLY);只播放一次.有人可以解决这个问题吗?

my problem is that timeUp.loop(timeUp.LOOP_CONTINUOUSLY); only plays it once. Can someone solve this?

推荐答案

您需要使用JavaSound API(javax.sound.*包中的类). Google将为您提供一些使用方法的教程.

You need to use the JavaSound API (classes in the javax.sound.* packages). Google will give you several tutorials on how to use them.

这篇关于Java中的更多高级音频控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆