All pastes #405356 Raw Edit

Sargun

public java v1 · immutable
·published 2007-03-21 18:08 UTC
rendered paste body
import apcslib.*;import chn.util.*;import javax.swing.*;import java.awt.*;import java.applet.*;import javax.sound.sampled.*; import java.io.*; import javax.sound.midi.*; import javax.sound.midi.MidiDevice.*;public class Sound extends Applet {  	Sequencer background = null;   public void test(int track){   	loadSound(track);   }    private  void loadSound(int track)   {   /*		Clip clip;   		AudioInputStream stream = null;		try {        // From file        if(track == 1){    	   stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\Pong\\sound\\dead.au"));    	}    	if(track == 2){    		  stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\fire.wav"));    	}    	if(track == 3){    	   stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\game2.wav"));		    	}        if(track == 5){  	       stream = AudioSystem.getAudioInputStream(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\nosoup.wav"));	        } //       AudioInputStream stream = AudioSystem.getAudioInputStream(new File("ding"));            // From URL        //stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));            // At present, ALAW and ULAW encodings must be converted        // to PCM_SIGNED before it can be played             if(stream != null){        	        AudioFormat format = stream.getFormat();        if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {            format = new AudioFormat(                    AudioFormat.Encoding.PCM_SIGNED,                    format.getSampleRate(),                    format.getSampleSizeInBits()*2,                    format.getChannels(),                    format.getFrameSize()*2,                    format.getFrameRate(),                    true);        // big endian            stream = AudioSystem.getAudioInputStream(format, stream);        }         // Create the clip        DataLine.Info info = new DataLine.Info(            Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));        clip = (Clip) AudioSystem.getLine(info);    	        // This method does not return until the audio file is completely loaded        clip.open(stream);    	System.out.println("Clip is: " + clip);    	clip.start();    	}        // Start playing        if(track == 4){        	    				Sequence sequence = MidiSystem.getSequence(new File("C:\\Documents and Settings\\crussell_m\\Desktop\\Pong\\sound\\jolene.mid"));    		      	background = MidiSystem.getSequencer();        			background.open();        			background.setSequence(sequence);        			background.setLoopCount(javax.sound.midi.Sequencer.LOOP_CONTINUOUSLY);        			//background.setLoopCount(10000);        			background.start();    	}    //} catch (MalformedURLException e) {    //} catch (IOException e) {    //} catch (LineUnavailableException e) {    } catch (Exception e) {    	System.out.println("Problem with sound loading \n"+ e);    	e.printStackTrace();    }		System.out.println("sound is loaded");	}	public void stop(){		background.stop();*/	}}