-1

Well I made this sound class that works with clips and i noticed the problem with large files. I saw that people have been talking about a class called BigClip which is the same as Clip just capable of handling big files...

My question is where can i get that class.. I noticed it doesnt come with normal java XD also how to i implent it into my code..

here is my code:

package org.game.engine;

import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

//Declaring all the fields
public class SoundEngine {
private Clip clip;
private  AudioInputStream sound;
private boolean stoped = false;
private DataLine.Info info;
private File soundFile;

//Constructor for a sound
 public SoundEngine(String filename) throws Exception {

// specify the sound to play
soundFile = new File(filename);
sound = AudioSystem.getAudioInputStream(soundFile);

// load the sound into a clip
info = new DataLine.Info(Clip.class, sound.getFormat());
clip = (Clip) AudioSystem.getLine(info);
System.out.println( Integer.toString(clip.getBufferSize()));
clip.open(sound);
}


    //Method do start/play the sound once
    public void start() throws LineUnavailableException, IOException, UnsupportedAudioFileException{
        if (stoped) {
             sound = AudioSystem.getAudioInputStream(soundFile);
             info = new DataLine.Info(Clip.class, sound.getFormat());
             clip = (Clip) AudioSystem.getLine(info);
             clip.open(sound);
             stoped = false;
        }
        clip.start();
    }


    //Method do pause the sound
    public void pause() {
        clip.stop();
    }



    //Method to fully stop the sound
    public void stop() {
        //make sure sound reloads it self because of the full stop
        stoped = true;
        //closes and drains
        clip.close();
        clip.drain();  
    }



    //Methd for looping sounds
    public void loop() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
          if (stoped) {
              //reloads the sound incase the sound is fully stoped
                     sound = AudioSystem.getAudioInputStream(soundFile);
                     info = new DataLine.Info(Clip.class, sound.getFormat());
                     clip = (Clip) AudioSystem.getLine(info);
                     clip.open(sound);
                     stoped = false;
          }
          //starts the looping
        clip.loop(Clip.LOOP_CONTINUOUSLY);
    }


   }        
Amit
  • 1
  • 1
  • 1
    Ask @[Andrew Thompson](http://stackoverflow.com/users/418556/andrew-thompson) since he developed it – MByD Aug 16 '11 at 15:50

1 Answers1

2

The code of BigClip is shown on my answer to this question.

It is necessary to compile it for your own use. There is no pre-built Jar you can add to the class-path. (OK, there is a pre-built Jar, but not that I am offering for others to use - brew your own).

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433