Mercurial > hg > ristipolku
annotate 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 |
rev | line source |
---|---|
22 | 1 /* |
2 * Ristipolku Game Engine | |
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> | |
4 */ | |
5 package game; | |
6 | |
7 import java.util.*; | |
8 import java.io.*; | |
9 import game.*; | |
10 import javax.sound.sampled.*; | |
11 | |
12 | |
13 class SoundElement implements Runnable | |
14 { | |
15 private final String name; | |
16 | |
17 private AudioInputStream stream; | |
18 private AudioFormat format; | |
19 private SourceDataLine line; | |
20 private Thread playThread; | |
21 private int loopCount; | |
22 private boolean playing, streaming; | |
23 private int volume = 100; | |
24 | |
25 byte[] buffer; | |
26 int length; | |
27 | |
28 | |
29 SoundElement(String filename, boolean streaming) throws IOException | |
30 { | |
31 this.name = filename; | |
32 this.streaming = streaming; | |
33 | |
23
0741dc117808
Remove sound code for later refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
34 /* |
22 | 35 ResourceLoader res = new ResourceLoader(name); |
36 if (res == null || res.getStream() == null) | |
37 { | |
38 throw new IOException("Could not load audio resource '"+name+"'.\n"); | |
39 } | |
40 | |
41 | |
42 try { | |
43 stream = AudioSystem.getAudioInputStream(res.getStream()); | |
44 format = stream.getFormat(); | |
45 } | |
46 catch (UnsupportedAudioFileException e) { | |
47 throw new IOException("Unsupported audio file format for '"+name+"'.\n"); | |
48 } | |
49 catch (IOException e) | |
50 { | |
51 throw new IOException("Could not load audio resource '"+name+"'.\n"); | |
52 } | |
53 | |
54 | |
55 if (streaming) { | |
56 System.out.print("Loading '"+name+"' as a clip\n"); | |
57 try { | |
58 clip = AudioSystem.getClip(); | |
59 clip.open(stream); | |
60 } | |
61 catch (LineUnavailableException e) | |
62 { | |
63 throw new IOException("Line unavailable for '"+name+"'.\n"); | |
64 } | |
65 finally { | |
66 stream.close(); | |
67 } | |
68 } | |
69 else | |
70 { | |
71 clip = null; | |
72 System.out.print("Loading '"+name+"' as stream\n"); | |
73 | |
74 try { | |
75 SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, format); | |
76 System.out.print("info: "+stream.getFrameLength() + ", " + format.getFrameSize() + "\n"); | |
77 line = (SourceDataLine) AudioSystem.getLine(info); | |
78 line.open(format); | |
79 } | |
80 catch (LineUnavailableException e) { | |
81 throw new IOException("Line unavailable for '"+name+"'.\n"); | |
82 } | |
83 } | |
23
0741dc117808
Remove sound code for later refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
84 */ |
22 | 85 } |
86 | |
87 public void play() | |
88 { | |
89 System.out.print("Sound("+name+").play()\n"); | |
90 } | |
91 | |
92 public void loop(int n) | |
93 { | |
94 System.out.print("Sound("+name+").loop("+n+")\n"); | |
95 } | |
96 | |
97 public void stop() | |
98 { | |
99 } | |
100 | |
101 public boolean isPlaying() | |
102 { | |
23
0741dc117808
Remove sound code for later refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
103 return false; |
22 | 104 } |
105 | |
106 public void run() | |
107 { | |
108 } | |
109 } |