0

My current project involves playing music, and I found a useful working code to play .wav sound files, but how can I speed the sound up, raise or lower the volume, and mute the sound. Is there commands or methods I have to use? Here is what I'm currently using.

import java.io.*;
import javax.sound.sampled.*;
try {
    AudioInputStream stream;
    AudioFormat format;
    DataLine.Info info;
    Clip clip;
    File file1 = new File("C:\\Users\\Bryce\\Desktop\\DM Galaxy.wav");
    stream = AudioSystem.getAudioInputStream(file1);
    format = stream.getFormat();
    info = new DataLine.Info(Clip.class, format);
    clip = (Clip) AudioSystem.getLine(info);
    clip.open(stream);
    clip.start();
} catch (Exception e) {
    e.printStackTrace();
}

This works great, but the only problem is, it plays it at full blast, and sounds very slow comapaired to if I just play the audio file. Any sugestions?

Bryce Hahn
  • 1,585
  • 4
  • 16
  • 26
  • You have a lot of questions at once. For volume control / mute, see http://stackoverflow.com/questions/953598/audio-volume-control-increase-or-decrease-in-java – Jason C Mar 29 '14 at 04:26
  • 1
    For playback speed, perhaps a solution similar to that link but with `FloatControl.Type.SAMPLE_RATE`. As for your speed issue; for some reason the playback sample rate seems off. Perhaps somebody with more knowledge of `javax.sound` can answer that one. – Jason C Mar 29 '14 at 04:29
  • Any Ideas on how to stop sound. Because I've already tried `clip.stop();` but it doesn't seem to work. Any ideas? @JasonC – Bryce Hahn Mar 29 '14 at 05:25

0 Answers0