Mercurial > hg > ristipolku
diff 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 diff
--- a/game/SoundElement.java Mon Jan 31 21:28:59 2011 +0200 +++ b/game/SoundElement.java Tue Feb 01 09:55:09 2011 +0200 @@ -31,6 +31,7 @@ this.name = filename; this.streaming = streaming; +/* ResourceLoader res = new ResourceLoader(name); if (res == null || res.getStream() == null) { @@ -80,110 +81,29 @@ throw new IOException("Line unavailable for '"+name+"'.\n"); } } +*/ } public void play() { System.out.print("Sound("+name+").play()\n"); - if (streaming) - { - clip.setFramePosition(0); - clip.start(); - } - else - { - if (playThread == null) - { - doPlay = true; - loopCount = 1; - playThread = new Thread(this); - playThread.start(); - } - } } public void loop(int n) { System.out.print("Sound("+name+").loop("+n+")\n"); - if (isClip()) - { - clip.setFramePosition(0); - if (n < 0) - clip.loop(Clip.LOOP_CONTINUOUSLY); - else - clip.loop(n); - } - else - { - if (playThread == null) - { - doPlay = true; - loopCount = n; - playThread = new Thread(this); - playThread.start(); - } - } } public void stop() { - if (isClip()) - { - if (clip.isRunning()) - clip.stop(); - } - else - { - if (playThread != null) - { - playThread.interrupt(); - doPlay = false; - playThread = null; - } - } } public boolean isPlaying() { - if (isClip()) - return clip.isRunning(); - else - return (playThread != null && line.isRunning()); + return false; } public void run() { - line.start(); - byte[] buf = new byte[line.getBufferSize()]; - - while (doPlay && (loopCount > 0 || loopCount == -1)) - { - try { - int numRead = 0; - while ((numRead = stream.read(buf, 0, buf.length)) >= 0 && doPlay) - { - int offset = 0; - while (offset < numRead) - { - System.out.print("audioThread: offs="+offset+", numread="+numRead+"\n"); - offset += line.write(buf, offset, numRead - offset); - } - } - line.drain(); - - System.out.print("audioThread: stream.reset()\n"); - stream.reset(); - } - catch (IOException e) { - } - - if (loopCount > 0) - loopCount--; - } - - line.stop(); - doPlay = false; } } - -