summaryrefslogtreecommitdiff
path: root/songdbj/javazoom/jl/player
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/javazoom/jl/player')
-rw-r--r--songdbj/javazoom/jl/player/AudioDevice.java103
-rw-r--r--songdbj/javazoom/jl/player/AudioDeviceBase.java177
-rw-r--r--songdbj/javazoom/jl/player/AudioDeviceFactory.java87
-rw-r--r--songdbj/javazoom/jl/player/FactoryRegistry.java129
-rw-r--r--songdbj/javazoom/jl/player/JavaSoundAudioDevice.java215
-rw-r--r--songdbj/javazoom/jl/player/JavaSoundAudioDeviceFactory.java85
-rw-r--r--songdbj/javazoom/jl/player/NullAudioDevice.java37
-rw-r--r--songdbj/javazoom/jl/player/Player.java251
-rw-r--r--songdbj/javazoom/jl/player/PlayerApplet.java246
-rw-r--r--songdbj/javazoom/jl/player/advanced/AdvancedPlayer.java242
-rw-r--r--songdbj/javazoom/jl/player/advanced/PlaybackEvent.java51
-rw-r--r--songdbj/javazoom/jl/player/advanced/PlaybackListener.java30
-rw-r--r--songdbj/javazoom/jl/player/advanced/jlap.java116
-rw-r--r--songdbj/javazoom/jl/player/jlp.java176
14 files changed, 0 insertions, 1945 deletions
diff --git a/songdbj/javazoom/jl/player/AudioDevice.java b/songdbj/javazoom/jl/player/AudioDevice.java
deleted file mode 100644
index 45c28600e6..0000000000
--- a/songdbj/javazoom/jl/player/AudioDevice.java
+++ /dev/null
@@ -1,103 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 29/01/00 Initial version. mdm@techie.com
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.player;
22
23import javazoom.jl.decoder.Decoder;
24import javazoom.jl.decoder.JavaLayerException;
25
26/**
27 * The <code>AudioDevice</code> interface provides an abstraction for
28 * a device capable of sounding audio samples. Samples are written to
29 * the device wia the write() method. The device assumes
30 * that these samples are signed 16-bit samples taken at the output frequency
31 * of the decoder. If the decoder outputs more than one channel, the samples for
32 * each channel are assumed to appear consecutively, with the lower numbered
33 * channels preceeding higher-numbered channels. E.g. if there are two
34 * channels, the samples will appear in this order:
35 * <pre><code>
36 *
37 * l0, r0, l1, r1, l2, r2...
38 *
39 * where
40 * l<i>x</i> indicates the <i>x</i>th sample on channel 0
41 * r<i>x</i> indicates the <i>x</i>th sample on channel 1
42 * </code></pre>
43 *
44 * @since 0.0.8
45 * @author Mat McGowan
46 */
47public interface AudioDevice
48{
49 /**
50 * Prepares the AudioDevice for playback of audio samples.
51 * @param decoder The decoder that will be providing the audio
52 * samples.
53 *
54 * If the audio device is already open, this method returns silently.
55 *
56 */
57 public void open(Decoder decoder) throws JavaLayerException;
58
59 /**
60 * Retrieves the open state of this audio device.
61 *
62 * @return <code>true</code> if this audio device is open and playing
63 * audio samples, or <code>false</code> otherwise.
64 */
65 public boolean isOpen();
66
67 /**
68 * Writes a number of samples to this <code>AudioDevice</code>.
69 *
70 * @param samples The array of signed 16-bit samples to write
71 * to the audio device.
72 * @param offs The offset of the first sample.
73 * @param len The number of samples to write.
74 *
75 * This method may return prior to the samples actually being played
76 * by the audio device.
77 */
78 public void write(short[] samples, int offs, int len) throws JavaLayerException;
79
80
81 /**
82 * Closes this audio device. Any currently playing audio is stopped
83 * as soon as possible. Any previously written audio data that has not been heard
84 * is discarded.
85 *
86 * The implementation should ensure that any threads currently blocking
87 * on the device (e.g. during a <code>write</code> or <code>flush</code>
88 * operation should be unblocked by this method.
89 */
90 public void close();
91
92
93 /**
94 * Blocks until all audio samples previously written to this audio device have
95 * been heard.
96 */
97 public void flush();
98
99 /**
100 * Retrieves the current playback position in milliseconds.
101 */
102 public int getPosition();
103}
diff --git a/songdbj/javazoom/jl/player/AudioDeviceBase.java b/songdbj/javazoom/jl/player/AudioDeviceBase.java
deleted file mode 100644
index d9c84f08e7..0000000000
--- a/songdbj/javazoom/jl/player/AudioDeviceBase.java
+++ /dev/null
@@ -1,177 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 29/01/00 Initial version. mdm@techie.com
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.player;
22
23import javazoom.jl.decoder.Decoder;
24import javazoom.jl.decoder.JavaLayerException;
25
26/**
27 * The <code>AudioDeviceBase</code> class provides a simple thread-safe
28 * implementation of the <code>AudioDevice</code> interface.
29 * Template methods are provided for subclasses to override and
30 * in doing so provide the implementation for the main operations
31 * of the <code>AudioDevice</code> interface.
32 *
33 * @since 0.0.8
34 * @author Mat McGowan
35 */
36/*
37 * REVIEW: It is desirable to be able to use the decoder whe
38 * in the implementation of open(), but the decoder
39 * has not yet read a frame, and so much of the
40 * desired information (sample rate, channels etc.)
41 * are not available.
42 */
43public abstract class AudioDeviceBase implements AudioDevice
44{
45 private boolean open = false;
46
47 private Decoder decoder = null;
48
49 /**
50 * Opens this audio device.
51 *
52 * @param decoder The decoder that will provide audio data
53 * to this audio device.
54 */
55 public synchronized void open(Decoder decoder) throws JavaLayerException
56 {
57 if (!isOpen())
58 {
59 this.decoder = decoder;
60 openImpl();
61 setOpen(true);
62 }
63 }
64
65 /**
66 * Template method to provide the
67 * implementation for the opening of the audio device.
68 */
69 protected void openImpl() throws JavaLayerException
70 {
71 }
72
73 /**
74 * Sets the open state for this audio device.
75 */
76 protected void setOpen(boolean open)
77 {
78 this.open = open;
79 }
80
81 /**
82 * Determines if this audio device is open or not.
83 *
84 * @return <code>true</code> if the audio device is open,
85 * <code>false</code> if it is not.
86 */
87 public synchronized boolean isOpen()
88 {
89 return open;
90 }
91
92 /**
93 * Closes this audio device. If the device is currently playing
94 * audio, playback is stopped immediately without flushing
95 * any buffered audio data.
96 */
97 public synchronized void close()
98 {
99 if (isOpen())
100 {
101 closeImpl();
102 setOpen(false);
103 decoder = null;
104 }
105 }
106
107 /**
108 * Template method to provide the implementation for
109 * closing the audio device.
110 */
111 protected void closeImpl()
112 {
113 }
114
115 /**
116 * Writes audio data to this audio device. Audio data is
117 * assumed to be in the output format of the decoder. This
118 * method may return before the data has actually been sounded
119 * by the device if the device buffers audio samples.
120 *
121 * @param samples The samples to write to the audio device.
122 * @param offs The offset into the array of the first sample to write.
123 * @param len The number of samples from the array to write.
124 * @throws JavaLayerException if the audio data could not be
125 * written to the audio device.
126 * If the audio device is not open, this method does nthing.
127 */
128 public void write(short[] samples, int offs, int len)
129 throws JavaLayerException
130 {
131 if (isOpen())
132 {
133 writeImpl(samples, offs, len);
134 }
135 }
136
137 /**
138 * Template method to provide the implementation for
139 * writing audio samples to the audio device.
140 */
141 protected void writeImpl(short[] samples, int offs, int len)
142 throws JavaLayerException
143 {
144 }
145
146 /**
147 * Waits for any buffered audio samples to be played by the
148 * audio device. This method should only be called prior
149 * to closing the device.
150 */
151 public void flush()
152 {
153 if (isOpen())
154 {
155 flushImpl();
156 }
157 }
158
159 /**
160 * Template method to provide the implementation for
161 * flushing any buffered audio data.
162 */
163 protected void flushImpl()
164 {
165 }
166
167 /**
168 * Retrieves the decoder that provides audio data to this
169 * audio device.
170 *
171 * @return The associated decoder.
172 */
173 protected Decoder getDecoder()
174 {
175 return decoder;
176 }
177}
diff --git a/songdbj/javazoom/jl/player/AudioDeviceFactory.java b/songdbj/javazoom/jl/player/AudioDeviceFactory.java
deleted file mode 100644
index 2d502d2aad..0000000000
--- a/songdbj/javazoom/jl/player/AudioDeviceFactory.java
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 29/01/00 Initial version. mdm@techie.com
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.player;
22
23import javazoom.jl.decoder.JavaLayerException;
24
25/**
26 * An <code>AudioDeviceFactory</code> class is responsible for creating
27 * a specific <code>AudioDevice</code> implementation. A factory implementation
28 * can be as simple or complex as desired and may support just one implementation
29 * or may return several implementations depending upon the execution
30 * environment.
31 * <p>
32 * When implementing a factory that provides an AudioDevice that uses
33 * class that may not be present, the factory should dynamically link to any
34 * specific implementation classes required to instantiate or test the audio
35 * implementation. This is so that the application as a whole
36 * can run without these classes being present. The audio
37 * device implementation, however, will usually statically link to the classes
38 * required. (See the JavaSound deivce and factory for an example
39 * of this.)
40 *
41 * @see FactoryRegistry
42 *
43 * @since 0.0.8
44 * @author Mat McGowan
45 */
46public abstract class AudioDeviceFactory
47{
48 /**
49 * Creates a new <code>AudioDevice</code>.
50 *
51 * @return a new instance of a specific class of <code>AudioDevice</code>.
52 * @throws JavaLayerException if an instance of AudioDevice could not
53 * be created.
54 */
55 public abstract AudioDevice createAudioDevice() throws JavaLayerException;
56
57 /**
58 * Creates an instance of an AudioDevice implementation.
59 * @param loader The <code>ClassLoader</code> to use to
60 * load the named class, or null to use the
61 * system class loader.
62 * @param name The name of the class to load.
63 * @return A newly-created instance of the audio device class.
64 */
65 protected AudioDevice instantiate(ClassLoader loader, String name)
66 throws ClassNotFoundException,
67 IllegalAccessException,
68 InstantiationException
69 {
70 AudioDevice dev = null;
71
72 Class cls = null;
73 if (loader==null)
74 {
75 cls = Class.forName(name);
76 }
77 else
78 {
79 cls = loader.loadClass(name);
80 }
81
82 Object o = cls.newInstance();
83 dev = (AudioDevice)o;
84
85 return dev;
86 }
87}
diff --git a/songdbj/javazoom/jl/player/FactoryRegistry.java b/songdbj/javazoom/jl/player/FactoryRegistry.java
deleted file mode 100644
index 8919995802..0000000000
--- a/songdbj/javazoom/jl/player/FactoryRegistry.java
+++ /dev/null
@@ -1,129 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 29/01/00 Initial version. mdm@techie.com
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.player;
22
23import java.util.Enumeration;
24import java.util.Hashtable;
25
26import javazoom.jl.decoder.JavaLayerException;
27
28/**
29 * The <code>FactoryRegistry</code> class stores the factories
30 * for all the audio device implementations available in the system.
31 * <p>
32 * Instances of this class are thread-safe.
33 *
34 * @since 0.0.8
35 * @author Mat McGowan
36 */
37
38public class FactoryRegistry extends AudioDeviceFactory
39{
40 static private FactoryRegistry instance = null;
41
42 static synchronized public FactoryRegistry systemRegistry()
43 {
44 if (instance==null)
45 {
46 instance = new FactoryRegistry();
47 instance.registerDefaultFactories();
48 }
49 return instance;
50 }
51
52
53 protected Hashtable factories = new Hashtable();
54
55 /**
56 * Registers an <code>AudioDeviceFactory</code> instance
57 * with this registry.
58 */
59 public void addFactory(AudioDeviceFactory factory)
60 {
61 factories.put(factory.getClass(), factory);
62 }
63
64 public void removeFactoryType(Class cls)
65 {
66 factories.remove(cls);
67 }
68
69 public void removeFactory(AudioDeviceFactory factory)
70 {
71 factories.remove(factory.getClass());
72 }
73
74 public AudioDevice createAudioDevice() throws JavaLayerException
75 {
76 AudioDevice device = null;
77 AudioDeviceFactory[] factories = getFactoriesPriority();
78
79 if (factories==null)
80 throw new JavaLayerException(this+": no factories registered");
81
82 JavaLayerException lastEx = null;
83 for (int i=0; (device==null) && (i<factories.length); i++)
84 {
85 try
86 {
87 device = factories[i].createAudioDevice();
88 }
89 catch (JavaLayerException ex)
90 {
91 lastEx = ex;
92 }
93 }
94
95 if (device==null && lastEx!=null)
96 {
97 throw new JavaLayerException("Cannot create AudioDevice", lastEx);
98 }
99
100 return device;
101 }
102
103
104 protected AudioDeviceFactory[] getFactoriesPriority()
105 {
106 AudioDeviceFactory[] fa = null;
107 synchronized (factories)
108 {
109 int size = factories.size();
110 if (size!=0)
111 {
112 fa = new AudioDeviceFactory[size];
113 int idx = 0;
114 Enumeration e = factories.elements();
115 while (e.hasMoreElements())
116 {
117 AudioDeviceFactory factory = (AudioDeviceFactory)e.nextElement();
118 fa[idx++] = factory;
119 }
120 }
121 }
122 return fa;
123 }
124
125 protected void registerDefaultFactories()
126 {
127 addFactory(new JavaSoundAudioDeviceFactory());
128 }
129}
diff --git a/songdbj/javazoom/jl/player/JavaSoundAudioDevice.java b/songdbj/javazoom/jl/player/JavaSoundAudioDevice.java
deleted file mode 100644
index caa92cd6fc..0000000000
--- a/songdbj/javazoom/jl/player/JavaSoundAudioDevice.java
+++ /dev/null
@@ -1,215 +0,0 @@
1/*
2 * 11/26/04 Buffer size modified to support JRE 1.5 optimizations.
3 * (CPU usage < 1% under P4/2Ghz, RAM < 12MB).
4 * jlayer@javazoom.net
5 * 11/19/04 1.0 moved to LGPL.
6 * 06/04/01 Too fast playback fixed. mdm@techie.com
7 * 29/01/00 Initial version. mdm@techie.com
8 *-----------------------------------------------------------------------
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Library General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *----------------------------------------------------------------------
23 */
24
25package javazoom.jl.player;
26
27import javax.sound.sampled.AudioFormat;
28import javax.sound.sampled.AudioSystem;
29import javax.sound.sampled.DataLine;
30import javax.sound.sampled.Line;
31import javax.sound.sampled.LineUnavailableException;
32import javax.sound.sampled.SourceDataLine;
33
34import javazoom.jl.decoder.Decoder;
35import javazoom.jl.decoder.JavaLayerException;
36
37/**
38 * The <code>JavaSoundAudioDevice</code> implements an audio
39 * device by using the JavaSound API.
40 *
41 * @since 0.0.8
42 * @author Mat McGowan
43 */
44public class JavaSoundAudioDevice extends AudioDeviceBase
45{
46 private SourceDataLine source = null;
47
48 private AudioFormat fmt = null;
49
50 private byte[] byteBuf = new byte[4096];
51
52 protected void setAudioFormat(AudioFormat fmt0)
53 {
54 fmt = fmt0;
55 }
56
57 protected AudioFormat getAudioFormat()
58 {
59 if (fmt==null)
60 {
61 Decoder decoder = getDecoder();
62 fmt = new AudioFormat(decoder.getOutputFrequency(),
63 16,
64 decoder.getOutputChannels(),
65 true,
66 false);
67 }
68 return fmt;
69 }
70
71 protected DataLine.Info getSourceLineInfo()
72 {
73 AudioFormat fmt = getAudioFormat();
74 //DataLine.Info info = new DataLine.Info(SourceDataLine.class, fmt, 4000);
75 DataLine.Info info = new DataLine.Info(SourceDataLine.class, fmt);
76 return info;
77 }
78
79 public void open(AudioFormat fmt) throws JavaLayerException
80 {
81 if (!isOpen())
82 {
83 setAudioFormat(fmt);
84 openImpl();
85 setOpen(true);
86 }
87 }
88
89 protected void openImpl()
90 throws JavaLayerException
91 {
92 }
93
94
95 // createSource fix.
96 protected void createSource() throws JavaLayerException
97 {
98 Throwable t = null;
99 try
100 {
101 Line line = AudioSystem.getLine(getSourceLineInfo());
102 if (line instanceof SourceDataLine)
103 {
104 source = (SourceDataLine)line;
105 //source.open(fmt, millisecondsToBytes(fmt, 2000));
106 source.open(fmt);
107 /*
108 if (source.isControlSupported(FloatControl.Type.MASTER_GAIN))
109 {
110 FloatControl c = (FloatControl)source.getControl(FloatControl.Type.MASTER_GAIN);
111 c.setValue(c.getMaximum());
112 }*/
113 source.start();
114
115 }
116 } catch (RuntimeException ex)
117 {
118 t = ex;
119 }
120 catch (LinkageError ex)
121 {
122 t = ex;
123 }
124 catch (LineUnavailableException ex)
125 {
126 t = ex;
127 }
128 if (source==null) throw new JavaLayerException("cannot obtain source audio line", t);
129 }
130
131 public int millisecondsToBytes(AudioFormat fmt, int time)
132 {
133 return (int)(time*(fmt.getSampleRate()*fmt.getChannels()*fmt.getSampleSizeInBits())/8000.0);
134 }
135
136 protected void closeImpl()
137 {
138 if (source!=null)
139 {
140 source.close();
141 }
142 }
143
144 protected void writeImpl(short[] samples, int offs, int len)
145 throws JavaLayerException
146 {
147 if (source==null)
148 createSource();
149
150 byte[] b = toByteArray(samples, offs, len);
151 source.write(b, 0, len*2);
152 }
153
154 protected byte[] getByteArray(int length)
155 {
156 if (byteBuf.length < length)
157 {
158 byteBuf = new byte[length+1024];
159 }
160 return byteBuf;
161 }
162
163 protected byte[] toByteArray(short[] samples, int offs, int len)
164 {
165 byte[] b = getByteArray(len*2);
166 int idx = 0;
167 short s;
168 while (len-- > 0)
169 {
170 s = samples[offs++];
171 b[idx++] = (byte)s;
172 b[idx++] = (byte)(s>>>8);
173 }
174 return b;
175 }
176
177 protected void flushImpl()
178 {
179 if (source!=null)
180 {
181 source.drain();
182 }
183 }
184
185 public int getPosition()
186 {
187 int pos = 0;
188 if (source!=null)
189 {
190 pos = (int)(source.getMicrosecondPosition()/1000);
191 }
192 return pos;
193 }
194
195 /**
196 * Runs a short test by playing a short silent sound.
197 */
198 public void test()
199 throws JavaLayerException
200 {
201 try
202 {
203 open(new AudioFormat(22050, 16, 1, true, false));
204 short[] data = new short[22050/10];
205 write(data, 0, data.length);
206 flush();
207 close();
208 }
209 catch (RuntimeException ex)
210 {
211 throw new JavaLayerException("Device test failed: "+ex);
212 }
213
214 }
215}
diff --git a/songdbj/javazoom/jl/player/JavaSoundAudioDeviceFactory.java b/songdbj/javazoom/jl/player/JavaSoundAudioDeviceFactory.java
deleted file mode 100644
index 92af492f65..0000000000
--- a/songdbj/javazoom/jl/player/JavaSoundAudioDeviceFactory.java
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 29/01/00 Initial version. mdm@techie.com
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.player;
22
23import javazoom.jl.decoder.JavaLayerException;
24
25/**
26 * This class is responsible for creating instances of the
27 * JavaSoundAudioDevice. The audio device implementation is loaded
28 * and tested dynamically as not all systems will have support
29 * for JavaSound, or they may have the incorrect version.
30 */
31public class JavaSoundAudioDeviceFactory extends AudioDeviceFactory
32{
33 private boolean tested = false;
34
35 static private final String DEVICE_CLASS_NAME = "javazoom.jl.player.JavaSoundAudioDevice";
36
37 public synchronized AudioDevice createAudioDevice()
38 throws JavaLayerException
39 {
40 if (!tested)
41 {
42 testAudioDevice();
43 tested = true;
44 }
45
46 try
47 {
48 return createAudioDeviceImpl();
49 }
50 catch (Exception ex)
51 {
52 throw new JavaLayerException("unable to create JavaSound device: "+ex);
53 }
54 catch (LinkageError ex)
55 {
56 throw new JavaLayerException("unable to create JavaSound device: "+ex);
57 }
58 }
59
60 protected JavaSoundAudioDevice createAudioDeviceImpl()
61 throws JavaLayerException
62 {
63 ClassLoader loader = getClass().getClassLoader();
64 try
65 {
66 JavaSoundAudioDevice dev = (JavaSoundAudioDevice)instantiate(loader, DEVICE_CLASS_NAME);
67 return dev;
68 }
69 catch (Exception ex)
70 {
71 throw new JavaLayerException("Cannot create JavaSound device", ex);
72 }
73 catch (LinkageError ex)
74 {
75 throw new JavaLayerException("Cannot create JavaSound device", ex);
76 }
77
78 }
79
80 public void testAudioDevice() throws JavaLayerException
81 {
82 JavaSoundAudioDevice dev = createAudioDeviceImpl();
83 dev.test();
84 }
85}
diff --git a/songdbj/javazoom/jl/player/NullAudioDevice.java b/songdbj/javazoom/jl/player/NullAudioDevice.java
deleted file mode 100644
index 4145feecd4..0000000000
--- a/songdbj/javazoom/jl/player/NullAudioDevice.java
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * 11/19/04 1.0 moved o LGPL.
3 * 29/01/00 Initial version. mdm@techie.com
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.player;
22
23/**
24 * The <code>NullAudioDevice</code> implements a silent, no-op
25 * audio device. This is useful for testing purposes.
26 *
27 * @since 0.0.8
28 * @author Mat McGowan
29 */
30public class NullAudioDevice extends AudioDeviceBase
31{
32
33 public int getPosition()
34 {
35 return 0;
36 }
37}
diff --git a/songdbj/javazoom/jl/player/Player.java b/songdbj/javazoom/jl/player/Player.java
deleted file mode 100644
index 32fb1f3051..0000000000
--- a/songdbj/javazoom/jl/player/Player.java
+++ /dev/null
@@ -1,251 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 29/01/00 Initial version. mdm@techie.com
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.player;
22
23import java.io.InputStream;
24
25import javazoom.jl.decoder.Bitstream;
26import javazoom.jl.decoder.BitstreamException;
27import javazoom.jl.decoder.Decoder;
28import javazoom.jl.decoder.Header;
29import javazoom.jl.decoder.JavaLayerException;
30import javazoom.jl.decoder.SampleBuffer;
31
32/**
33 * The <code>Player</code> class implements a simple player for playback
34 * of an MPEG audio stream.
35 *
36 * @author Mat McGowan
37 * @since 0.0.8
38 */
39
40// REVIEW: the audio device should not be opened until the
41// first MPEG audio frame has been decoded.
42public class Player
43{
44 /**
45 * The current frame number.
46 */
47 private int frame = 0;
48
49 /**
50 * The MPEG audio bitstream.
51 */
52 // javac blank final bug.
53 /*final*/ private Bitstream bitstream;
54
55 /**
56 * The MPEG audio decoder.
57 */
58 /*final*/ private Decoder decoder;
59
60 /**
61 * The AudioDevice the audio samples are written to.
62 */
63 private AudioDevice audio;
64
65 /**
66 * Has the player been closed?
67 */
68 private boolean closed = false;
69
70 /**
71 * Has the player played back all frames from the stream?
72 */
73 private boolean complete = false;
74
75 private int lastPosition = 0;
76
77 /**
78 * Creates a new <code>Player</code> instance.
79 */
80 public Player(InputStream stream) throws JavaLayerException
81 {
82 this(stream, null);
83 }
84
85 public Player(InputStream stream, AudioDevice device) throws JavaLayerException
86 {
87 bitstream = new Bitstream(stream);
88 decoder = new Decoder();
89
90 if (device!=null)
91 {
92 audio = device;
93 }
94 else
95 {
96 FactoryRegistry r = FactoryRegistry.systemRegistry();
97 audio = r.createAudioDevice();
98 }
99 audio.open(decoder);
100 }
101
102 public void play() throws JavaLayerException
103 {
104 play(Integer.MAX_VALUE);
105 }
106
107 /**
108 * Plays a number of MPEG audio frames.
109 *
110 * @param frames The number of frames to play.
111 * @return true if the last frame was played, or false if there are
112 * more frames.
113 */
114 public boolean play(int frames) throws JavaLayerException
115 {
116 boolean ret = true;
117
118 while (frames-- > 0 && ret)
119 {
120 ret = decodeFrame();
121 }
122
123 if (!ret)
124 {
125 // last frame, ensure all data flushed to the audio device.
126 AudioDevice out = audio;
127 if (out!=null)
128 {
129 out.flush();
130 synchronized (this)
131 {
132 complete = (!closed);
133 close();
134 }
135 }
136 }
137 return ret;
138 }
139
140 /**
141 * Cloases this player. Any audio currently playing is stopped
142 * immediately.
143 */
144 public synchronized void close()
145 {
146 AudioDevice out = audio;
147 if (out!=null)
148 {
149 closed = true;
150 audio = null;
151 // this may fail, so ensure object state is set up before
152 // calling this method.
153 out.close();
154 lastPosition = out.getPosition();
155 try
156 {
157 bitstream.close();
158 }
159 catch (BitstreamException ex)
160 {
161 }
162 }
163 }
164
165 /**
166 * Returns the completed status of this player.
167 *
168 * @return true if all available MPEG audio frames have been
169 * decoded, or false otherwise.
170 */
171 public synchronized boolean isComplete()
172 {
173 return complete;
174 }
175
176 /**
177 * Retrieves the position in milliseconds of the current audio
178 * sample being played. This method delegates to the <code>
179 * AudioDevice</code> that is used by this player to sound
180 * the decoded audio samples.
181 */
182 public int getPosition()
183 {
184 int position = lastPosition;
185
186 AudioDevice out = audio;
187 if (out!=null)
188 {
189 position = out.getPosition();
190 }
191 return position;
192 }
193
194 /**
195 * Decodes a single frame.
196 *
197 * @return true if there are no more frames to decode, false otherwise.
198 */
199 protected boolean decodeFrame() throws JavaLayerException
200 {
201 try
202 {
203 AudioDevice out = audio;
204 if (out==null)
205 return false;
206
207 Header h = bitstream.readFrame();
208
209 if (h==null)
210 return false;
211
212 // sample buffer set when decoder constructed
213 SampleBuffer output = (SampleBuffer)decoder.decodeFrame(h, bitstream);
214
215 synchronized (this)
216 {
217 out = audio;
218 if (out!=null)
219 {
220 out.write(output.getBuffer(), 0, output.getBufferLength());
221 }
222 }
223
224 bitstream.closeFrame();
225 }
226 catch (RuntimeException ex)
227 {
228 throw new JavaLayerException("Exception decoding audio frame", ex);
229 }
230/*
231 catch (IOException ex)
232 {
233 System.out.println("exception decoding audio frame: "+ex);
234 return false;
235 }
236 catch (BitstreamException bitex)
237 {
238 System.out.println("exception decoding audio frame: "+bitex);
239 return false;
240 }
241 catch (DecoderException decex)
242 {
243 System.out.println("exception decoding audio frame: "+decex);
244 return false;
245 }
246*/
247 return true;
248 }
249
250
251}
diff --git a/songdbj/javazoom/jl/player/PlayerApplet.java b/songdbj/javazoom/jl/player/PlayerApplet.java
deleted file mode 100644
index d7c7dc2ffc..0000000000
--- a/songdbj/javazoom/jl/player/PlayerApplet.java
+++ /dev/null
@@ -1,246 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 29/01/00 Initial version. mdm@techie.com
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.player;
22
23import java.applet.Applet;
24import java.io.IOException;
25import java.io.InputStream;
26import java.net.URL;
27
28import javazoom.jl.decoder.JavaLayerException;
29
30/**
31 * A simple applet that plays an MPEG audio file.
32 * The URL (relative to the document base)
33 * is passed as the "audioURL" parameter.
34 *
35 * @author Mat McGowan
36 * @since 0.0.8
37 */
38public class PlayerApplet extends Applet implements Runnable
39{
40 static public final String AUDIO_PARAMETER = "audioURL";
41
42 /**
43 * The Player used to play the MPEG audio file.
44 */
45 private Player player = null;
46
47 /**
48 * The thread that runs the player.
49 */
50 private Thread playerThread = null;
51
52 private String fileName = null;
53
54
55 /**
56 * Retrieves the <code>AudioDevice</code> instance that will
57 * be used to sound the audio data.
58 *
59 * @return an audio device instance that will be used to
60 * sound the audio stream.
61 */
62 protected AudioDevice getAudioDevice() throws JavaLayerException
63 {
64 return FactoryRegistry.systemRegistry().createAudioDevice();
65 }
66
67 /**
68 * Retrieves the InputStream that provides the MPEG audio
69 * stream data.
70 *
71 * @return an InputStream from which the MPEG audio data
72 * is read, or null if an error occurs.
73 */
74 protected InputStream getAudioStream()
75 {
76 InputStream in = null;
77
78 try
79 {
80 URL url = getAudioURL();
81 if (url!=null)
82 in = url.openStream();
83 }
84 catch (IOException ex)
85 {
86 System.err.println(ex);
87 }
88 return in;
89 }
90
91 protected String getAudioFileName()
92 {
93 String urlString = fileName;
94 if (urlString==null)
95 {
96 urlString = getParameter(AUDIO_PARAMETER);
97 }
98 return urlString;
99 }
100
101 protected URL getAudioURL()
102 {
103 String urlString = getAudioFileName();
104 URL url = null;
105 if (urlString!=null)
106 {
107 try
108 {
109 url = new URL(getDocumentBase(), urlString);
110 }
111 catch (Exception ex)
112 {
113 System.err.println(ex);
114 }
115 }
116 return url;
117 }
118
119 /**
120 * Sets the URL of the audio stream to play.
121 */
122 public void setFileName(String name)
123 {
124 fileName = name;
125 }
126
127 public String getFileName()
128 {
129 return fileName;
130 }
131
132 /**
133 * Stops the audio player. If the player is already stopped
134 * this method is a no-op.
135 */
136 protected void stopPlayer() throws JavaLayerException
137 {
138 if (player!=null)
139 {
140 player.close();
141 player = null;
142 playerThread = null;
143 }
144 }
145
146 /**
147 * Decompresses audio data from an InputStream and plays it
148 * back through an AudioDevice. The playback is run on a newly
149 * created thread.
150 *
151 * @param in The InputStream that provides the MPEG audio data.
152 * @param dev The AudioDevice to use to sound the decompressed data.
153 *
154 * @throws JavaLayerException if there was a problem decoding
155 * or playing the audio data.
156 */
157 protected void play(InputStream in, AudioDevice dev) throws JavaLayerException
158 {
159 stopPlayer();
160
161 if (in!=null && dev!=null)
162 {
163 player = new Player(in, dev);
164 playerThread = createPlayerThread();
165 playerThread.start();
166 }
167 }
168
169 /**
170 * Creates a new thread used to run the audio player.
171 * @return A new Thread that, once started, runs the audio player.
172 */
173 protected Thread createPlayerThread()
174 {
175 return new Thread(this, "Audio player thread");
176 }
177
178 /**
179 * Initializes this applet.
180 */
181 public void init()
182 {
183 }
184
185 /**
186 * Starts this applet. An input stream and audio device
187 * are created and passed to the play() method.
188 */
189 public void start()
190 {
191 String name = getAudioFileName();
192 try
193 {
194 InputStream in = getAudioStream();
195 AudioDevice dev = getAudioDevice();
196 play(in, dev);
197 }
198 catch (JavaLayerException ex)
199 {
200 synchronized (System.err)
201 {
202 System.err.println("Unable to play "+name);
203 ex.printStackTrace(System.err);
204 }
205 }
206 }
207
208 /**
209 * Stops this applet. If audio is currently playing, it is
210 * stopped.
211 */
212 public void stop()
213 {
214 try
215 {
216 stopPlayer();
217 }
218 catch (JavaLayerException ex)
219 {
220 System.err.println(ex);
221 }
222 }
223
224 public void destroy()
225 {
226 }
227
228 /**
229 * The run method for the audio player thread. Simply calls
230 * play() on the player to play the entire stream.
231 */
232 public void run()
233 {
234 if (player!=null)
235 {
236 try
237 {
238 player.play();
239 }
240 catch (JavaLayerException ex)
241 {
242 System.err.println("Problem playing audio: "+ex);
243 }
244 }
245 }
246}
diff --git a/songdbj/javazoom/jl/player/advanced/AdvancedPlayer.java b/songdbj/javazoom/jl/player/advanced/AdvancedPlayer.java
deleted file mode 100644
index 45a31e46e1..0000000000
--- a/songdbj/javazoom/jl/player/advanced/AdvancedPlayer.java
+++ /dev/null
@@ -1,242 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 *-----------------------------------------------------------------------
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published
6 * by the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *----------------------------------------------------------------------
18 */
19
20package javazoom.jl.player.advanced;
21
22import java.io.InputStream;
23
24import javazoom.jl.decoder.Bitstream;
25import javazoom.jl.decoder.BitstreamException;
26import javazoom.jl.decoder.Decoder;
27import javazoom.jl.decoder.Header;
28import javazoom.jl.decoder.JavaLayerException;
29import javazoom.jl.decoder.SampleBuffer;
30import javazoom.jl.player.AudioDevice;
31import javazoom.jl.player.FactoryRegistry;
32
33/**
34 * a hybrid of javazoom.jl.player.Player tweeked to include <code>play(startFrame, endFrame)</code>
35 * hopefully this will be included in the api
36 */
37public class AdvancedPlayer
38{
39 /** The MPEG audio bitstream.*/
40 private Bitstream bitstream;
41 /** The MPEG audio decoder. */
42 private Decoder decoder;
43 /** The AudioDevice the audio samples are written to. */
44 private AudioDevice audio;
45 /** Has the player been closed? */
46 private boolean closed = false;
47 /** Has the player played back all frames from the stream? */
48 private boolean complete = false;
49 private int lastPosition = 0;
50 /** Listener for the playback process */
51 private PlaybackListener listener;
52
53 /**
54 * Creates a new <code>Player</code> instance.
55 */
56 public AdvancedPlayer(InputStream stream) throws JavaLayerException
57 {
58 this(stream, null);
59 }
60
61 public AdvancedPlayer(InputStream stream, AudioDevice device) throws JavaLayerException
62 {
63 bitstream = new Bitstream(stream);
64
65 if (device!=null) audio = device;
66 else audio = FactoryRegistry.systemRegistry().createAudioDevice();
67 audio.open(decoder = new Decoder());
68 }
69
70 public void play() throws JavaLayerException
71 {
72 play(Integer.MAX_VALUE);
73 }
74
75 /**
76 * Plays a number of MPEG audio frames.
77 *
78 * @param frames The number of frames to play.
79 * @return true if the last frame was played, or false if there are
80 * more frames.
81 */
82 public boolean play(int frames) throws JavaLayerException
83 {
84 boolean ret = true;
85
86 // report to listener
87 if(listener != null) listener.playbackStarted(createEvent(PlaybackEvent.STARTED));
88
89 while (frames-- > 0 && ret)
90 {
91 ret = decodeFrame();
92 }
93
94// if (!ret)
95 {
96 // last frame, ensure all data flushed to the audio device.
97 AudioDevice out = audio;
98 if (out != null)
99 {
100// System.out.println(audio.getPosition());
101 out.flush();
102// System.out.println(audio.getPosition());
103 synchronized (this)
104 {
105 complete = (!closed);
106 close();
107 }
108
109 // report to listener
110 if(listener != null) listener.playbackFinished(createEvent(out, PlaybackEvent.STOPPED));
111 }
112 }
113 return ret;
114 }
115
116 /**
117 * Cloases this player. Any audio currently playing is stopped
118 * immediately.
119 */
120 public synchronized void close()
121 {
122 AudioDevice out = audio;
123 if (out != null)
124 {
125 closed = true;
126 audio = null;
127 // this may fail, so ensure object state is set up before
128 // calling this method.
129 out.close();
130 lastPosition = out.getPosition();
131 try
132 {
133 bitstream.close();
134 }
135 catch (BitstreamException ex)
136 {}
137 }
138 }
139
140 /**
141 * Decodes a single frame.
142 *
143 * @return true if there are no more frames to decode, false otherwise.
144 */
145 protected boolean decodeFrame() throws JavaLayerException
146 {
147 try
148 {
149 AudioDevice out = audio;
150 if (out == null) return false;
151
152 Header h = bitstream.readFrame();
153 if (h == null) return false;
154
155 // sample buffer set when decoder constructed
156 SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
157
158 synchronized (this)
159 {
160 out = audio;
161 if(out != null)
162 {
163 out.write(output.getBuffer(), 0, output.getBufferLength());
164 }
165 }
166
167 bitstream.closeFrame();
168 }
169 catch (RuntimeException ex)
170 {
171 throw new JavaLayerException("Exception decoding audio frame", ex);
172 }
173 return true;
174 }
175
176 /**
177 * skips over a single frame
178 * @return false if there are no more frames to decode, true otherwise.
179 */
180 protected boolean skipFrame() throws JavaLayerException
181 {
182 Header h = bitstream.readFrame();
183 if (h == null) return false;
184 bitstream.closeFrame();
185 return true;
186 }
187
188 /**
189 * Plays a range of MPEG audio frames
190 * @param start The first frame to play
191 * @param end The last frame to play
192 * @return true if the last frame was played, or false if there are more frames.
193 */
194 public boolean play(final int start, final int end) throws JavaLayerException
195 {
196 boolean ret = true;
197 int offset = start;
198 while (offset-- > 0 && ret) ret = skipFrame();
199 return play(end - start);
200 }
201
202 /**
203 * Constructs a <code>PlaybackEvent</code>
204 */
205 private PlaybackEvent createEvent(int id)
206 {
207 return createEvent(audio, id);
208 }
209
210 /**
211 * Constructs a <code>PlaybackEvent</code>
212 */
213 private PlaybackEvent createEvent(AudioDevice dev, int id)
214 {
215 return new PlaybackEvent(this, id, dev.getPosition());
216 }
217
218 /**
219 * sets the <code>PlaybackListener</code>
220 */
221 public void setPlayBackListener(PlaybackListener listener)
222 {
223 this.listener = listener;
224 }
225
226 /**
227 * gets the <code>PlaybackListener</code>
228 */
229 public PlaybackListener getPlayBackListener()
230 {
231 return listener;
232 }
233
234 /**
235 * closes the player and notifies <code>PlaybackListener</code>
236 */
237 public void stop()
238 {
239 listener.playbackFinished(createEvent(PlaybackEvent.STOPPED));
240 close();
241 }
242} \ No newline at end of file
diff --git a/songdbj/javazoom/jl/player/advanced/PlaybackEvent.java b/songdbj/javazoom/jl/player/advanced/PlaybackEvent.java
deleted file mode 100644
index 08e3cae958..0000000000
--- a/songdbj/javazoom/jl/player/advanced/PlaybackEvent.java
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 *-----------------------------------------------------------------------
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published
6 * by the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *----------------------------------------------------------------------
18 */
19
20package javazoom.jl.player.advanced;
21
22/**
23 * An event which indicates a <code>Player</code> has performed an 'playback action'
24 * @author Paul Stanton (http://wanto.f2o.org/)
25 */
26public class PlaybackEvent
27{
28 public static int STOPPED = 1;
29 public static int STARTED = 2;
30
31 private AdvancedPlayer source;
32 private int frame;
33 private int id;
34
35 public PlaybackEvent(AdvancedPlayer source, int id, int frame)
36 {
37 this.id = id;
38 this.source = source;
39 this.frame = frame;
40 }
41
42 public int getId(){return id;}
43 public void setId(int id){this.id = id;}
44
45 public int getFrame(){return frame;}
46 public void setFrame(int frame){this.frame = frame;}
47
48 public AdvancedPlayer getSource(){return source;}
49 public void setSource(AdvancedPlayer source){this.source = source;}
50
51}
diff --git a/songdbj/javazoom/jl/player/advanced/PlaybackListener.java b/songdbj/javazoom/jl/player/advanced/PlaybackListener.java
deleted file mode 100644
index 9b042988b8..0000000000
--- a/songdbj/javazoom/jl/player/advanced/PlaybackListener.java
+++ /dev/null
@@ -1,30 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 *-----------------------------------------------------------------------
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published
6 * by the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *----------------------------------------------------------------------
18 */
19
20package javazoom.jl.player.advanced;
21
22/**
23 * Listener for javalayer Player playback
24 * @author Paul Stanton (http://wanto.f2o.org/)
25 */
26public abstract class PlaybackListener
27{
28 public void playbackStarted(PlaybackEvent evt){}
29 public void playbackFinished(PlaybackEvent evt){}
30}
diff --git a/songdbj/javazoom/jl/player/advanced/jlap.java b/songdbj/javazoom/jl/player/advanced/jlap.java
deleted file mode 100644
index beedea6716..0000000000
--- a/songdbj/javazoom/jl/player/advanced/jlap.java
+++ /dev/null
@@ -1,116 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 *-----------------------------------------------------------------------
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published
6 * by the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *----------------------------------------------------------------------
18 */
19
20package javazoom.jl.player.advanced;
21
22import java.io.BufferedInputStream;
23import java.io.File;
24import java.io.FileInputStream;
25import java.io.IOException;
26import java.io.InputStream;
27
28import javazoom.jl.decoder.JavaLayerException;
29
30/**
31 * This class implements a sample player using Playback listener.
32 */
33public class jlap
34{
35
36 public static void main(String[] args)
37 {
38 jlap test = new jlap();
39 if (args.length != 1)
40 {
41 test.showUsage();
42 System.exit(0);
43 }
44 else
45 {
46 try
47 {
48 test.play(args[0]);
49 }
50 catch (Exception ex)
51 {
52 System.err.println(ex.getMessage());
53 System.exit(0);
54 }
55 }
56 }
57
58 public void play(String filename) throws JavaLayerException, IOException
59 {
60 InfoListener lst = new InfoListener();
61 playMp3(new File(filename), lst);
62 }
63
64 public void showUsage()
65 {
66 System.out.println("Usage: jla <filename>");
67 System.out.println("");
68 System.out.println(" e.g. : java javazoom.jl.player.advanced.jlap localfile.mp3");
69 }
70
71 public static AdvancedPlayer playMp3(File mp3, PlaybackListener listener) throws IOException, JavaLayerException
72 {
73 return playMp3(mp3, 0, Integer.MAX_VALUE, listener);
74 }
75
76 public static AdvancedPlayer playMp3(File mp3, int start, int end, PlaybackListener listener) throws IOException, JavaLayerException
77 {
78 return playMp3(new BufferedInputStream(new FileInputStream(mp3)), start, end, listener);
79 }
80
81 public static AdvancedPlayer playMp3(final InputStream is, final int start, final int end, PlaybackListener listener) throws JavaLayerException
82 {
83 final AdvancedPlayer player = new AdvancedPlayer(is);
84 player.setPlayBackListener(listener);
85 // run in new thread
86 new Thread()
87 {
88 public void run()
89 {
90 try
91 {
92 player.play(start, end);
93 }
94 catch (Exception e)
95 {
96 throw new RuntimeException(e.getMessage());
97 }
98 }
99 }.start();
100 return player;
101 }
102
103 public class InfoListener extends PlaybackListener
104 {
105 public void playbackStarted(PlaybackEvent evt)
106 {
107 System.out.println("Play started from frame " + evt.getFrame());
108 }
109
110 public void playbackFinished(PlaybackEvent evt)
111 {
112 System.out.println("Play completed at frame " + evt.getFrame());
113 System.exit(0);
114 }
115 }
116} \ No newline at end of file
diff --git a/songdbj/javazoom/jl/player/jlp.java b/songdbj/javazoom/jl/player/jlp.java
deleted file mode 100644
index ddb3d5ecca..0000000000
--- a/songdbj/javazoom/jl/player/jlp.java
+++ /dev/null
@@ -1,176 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 *
4 * 06/04/01 Streaming support added. javalayer@javazoom.net
5 *
6 * 29/01/00 Initial version. mdm@techie.com
7 *-----------------------------------------------------------------------
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Library General Public License as published
10 * by the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *----------------------------------------------------------------------
22 */
23
24package javazoom.jl.player;
25
26import java.io.BufferedInputStream;
27import java.io.FileInputStream;
28import java.io.IOException;
29import java.io.InputStream;
30import java.net.URL;
31
32import javazoom.jl.decoder.JavaLayerException;
33
34/**
35 * The <code>jlp</code> class implements a simple command-line
36 * player for MPEG audio files.
37 *
38 * @author Mat McGowan (mdm@techie.com)
39 */
40public class jlp
41{
42 private String fFilename = null;
43 private boolean remote = false;
44
45 public static void main(String[] args)
46 {
47 int retval = 0;
48 try
49 {
50 jlp player = createInstance(args);
51 if (player!=null)
52 player.play();
53 }
54 catch (Exception ex)
55 {
56 System.err.println(ex);
57 ex.printStackTrace(System.err);
58 retval = 1;
59 }
60 System.exit(retval);
61 }
62
63 static public jlp createInstance(String[] args)
64 {
65 jlp player = new jlp();
66 if (!player.parseArgs(args))
67 player = null;
68 return player;
69 }
70
71 private jlp()
72 {
73 }
74
75 public jlp(String filename)
76 {
77 init(filename);
78 }
79
80 protected void init(String filename)
81 {
82 fFilename = filename;
83 }
84
85 protected boolean parseArgs(String[] args)
86 {
87 boolean parsed = false;
88 if (args.length == 1)
89 {
90 init(args[0]);
91 parsed = true;
92 remote = false;
93 }
94 else if (args.length == 2)
95 {
96 if (!(args[0].equals("-url")))
97 {
98 showUsage();
99 }
100 else
101 {
102 init(args[1]);
103 parsed = true;
104 remote = true;
105 }
106 }
107 else
108 {
109 showUsage();
110 }
111 return parsed;
112 }
113
114 public void showUsage()
115 {
116 System.out.println("Usage: jlp [-url] <filename>");
117 System.out.println("");
118 System.out.println(" e.g. : java javazoom.jl.player.jlp localfile.mp3");
119 System.out.println(" java javazoom.jl.player.jlp -url http://www.server.com/remotefile.mp3");
120 System.out.println(" java javazoom.jl.player.jlp -url http://www.shoutcastserver.com:8000");
121 }
122
123 public void play()
124 throws JavaLayerException
125 {
126 try
127 {
128 System.out.println("playing "+fFilename+"...");
129 InputStream in = null;
130 if (remote == true) in = getURLInputStream();
131 else in = getInputStream();
132 AudioDevice dev = getAudioDevice();
133 Player player = new Player(in, dev);
134 player.play();
135 }
136 catch (IOException ex)
137 {
138 throw new JavaLayerException("Problem playing file "+fFilename, ex);
139 }
140 catch (Exception ex)
141 {
142 throw new JavaLayerException("Problem playing file "+fFilename, ex);
143 }
144 }
145
146 /**
147 * Playing file from URL (Streaming).
148 */
149 protected InputStream getURLInputStream()
150 throws Exception
151 {
152
153 URL url = new URL(fFilename);
154 InputStream fin = url.openStream();
155 BufferedInputStream bin = new BufferedInputStream(fin);
156 return bin;
157 }
158
159 /**
160 * Playing file from FileInputStream.
161 */
162 protected InputStream getInputStream()
163 throws IOException
164 {
165 FileInputStream fin = new FileInputStream(fFilename);
166 BufferedInputStream bin = new BufferedInputStream(fin);
167 return bin;
168 }
169
170 protected AudioDevice getAudioDevice()
171 throws JavaLayerException
172 {
173 return FactoryRegistry.systemRegistry().createAudioDevice();
174 }
175
176}