Mercurial > hg > ristipolku
view game/SoundElement.java @ 23:0741dc117808
Remove sound code for later refactoring.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 01 Feb 2011 09:55:09 +0200 |
parents | afde253ec705 |
children | 736de7b28701 |
line wrap: on
line source
/* * Ristipolku Game Engine * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> */ package game; import java.util.*; import java.io.*; import game.*; import javax.sound.sampled.*; class SoundElement implements Runnable { private final String name; private AudioInputStream stream; private AudioFormat format; private SourceDataLine line; private Thread playThread; private int loopCount; private boolean playing, streaming; private int volume = 100; byte[] buffer; int length; SoundElement(String filename, boolean streaming) throws IOException { this.name = filename; this.streaming = streaming; /* ResourceLoader res = new ResourceLoader(name); if (res == null || res.getStream() == null) { throw new IOException("Could not load audio resource '"+name+"'.\n"); } try { stream = AudioSystem.getAudioInputStream(res.getStream()); format = stream.getFormat(); } catch (UnsupportedAudioFileException e) { throw new IOException("Unsupported audio file format for '"+name+"'.\n"); } catch (IOException e) { throw new IOException("Could not load audio resource '"+name+"'.\n"); } if (streaming) { System.out.print("Loading '"+name+"' as a clip\n"); try { clip = AudioSystem.getClip(); clip.open(stream); } catch (LineUnavailableException e) { throw new IOException("Line unavailable for '"+name+"'.\n"); } finally { stream.close(); } } else { clip = null; System.out.print("Loading '"+name+"' as stream\n"); try { SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, format); System.out.print("info: "+stream.getFrameLength() + ", " + format.getFrameSize() + "\n"); line = (SourceDataLine) AudioSystem.getLine(info); line.open(format); } catch (LineUnavailableException e) { throw new IOException("Line unavailable for '"+name+"'.\n"); } } */ } public void play() { System.out.print("Sound("+name+").play()\n"); } public void loop(int n) { System.out.print("Sound("+name+").loop("+n+")\n"); } public void stop() { } public boolean isPlaying() { return false; } public void run() { } }