Skip to content

Commit 70984a9

Browse files
Deprecate open(Object)
It's better to know at compile time that you cannot call open(String). If open(Objet) is permitted, the error appears at runtime, not compile time.
1 parent fd27f0b commit 70984a9

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
import javax.sound.sampled.Mixer;
3030
import javax.sound.sampled.SourceDataLine;
3131
import javax.sound.sampled.UnsupportedAudioFileException;
32+
import java.io.File;
3233
import java.io.IOException;
34+
import java.io.InputStream;
35+
import java.net.URL;
3336
import java.nio.ByteBuffer;
3437
import java.nio.ByteOrder;
3538
import java.util.ArrayList;
@@ -248,15 +251,17 @@ public void removeStreamPlayerListener(final StreamPlayerListener streamPlayerLi
248251
* @param object the object [File or URL or InputStream ]
249252
*
250253
* @throws StreamPlayerException the stream player exception
254+
* @deprecated Use one of {@link #open(File)}, {@link #open(URL)} or {@link #open(InputStream)} instead.
255+
*
251256
*/
252257
@Override
258+
@Deprecated
253259
public void open(final Object object) throws StreamPlayerException {
254260

255261
logger.info(() -> "open(" + object + ")\n");
256262
if (object == null)
257263
return;
258264

259-
//source = new DataSource(object);
260265
try {
261266
source = DataSource.newDataSource(object);
262267
} catch (OperationNotSupportedException e) {
@@ -265,6 +270,46 @@ public void open(final Object object) throws StreamPlayerException {
265270
initAudioInputStream();
266271
}
267272

273+
/**
274+
* Open the specified file for playback.
275+
*
276+
* @param file the file to be played
277+
* @throws StreamPlayerException the stream player exception
278+
*/
279+
@Override
280+
public void open(File file) throws StreamPlayerException {
281+
282+
logger.info(() -> "open(" + file + ")\n");
283+
source = new FileDataSource(file);
284+
initAudioInputStream();
285+
}
286+
287+
/**
288+
* Open the specified location for playback.
289+
*
290+
* @param url the location to be played
291+
* @throws StreamPlayerException the stream player exception
292+
*/
293+
@Override
294+
public void open(URL url) throws StreamPlayerException {
295+
logger.info(() -> "open(" + url + ")\n");
296+
source = new UrlDataSource(url);
297+
initAudioInputStream();
298+
}
299+
300+
/**
301+
* Open the specified stream for playback.
302+
*
303+
* @param stream the stream to be played
304+
* @throws StreamPlayerException the stream player exception
305+
*/
306+
@Override
307+
public void open(InputStream stream) throws StreamPlayerException {
308+
logger.info(() -> "open(" + stream + ")\n");
309+
source = new StreamDataSource(stream);
310+
initAudioInputStream();
311+
}
312+
268313
/**
269314
* Create AudioInputStream and AudioFileFormat from the data source.
270315
*

src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerInterface.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import com.goxr3plus.streamplayer.enums.Status;
44

55
import javax.sound.sampled.SourceDataLine;
6+
import java.io.File;
7+
import java.io.InputStream;
8+
import java.net.URL;
69
import java.util.List;
7-
import java.util.concurrent.Callable;
810

911
public interface StreamPlayerInterface {
1012
/**
@@ -27,14 +29,43 @@ public interface StreamPlayerInterface {
2729
void removeStreamPlayerListener(StreamPlayerListener streamPlayerListener);
2830

2931
/**
30-
* Open the specific object which can be File,URL or InputStream.
32+
* Open the specified object which can be File,URL or InputStream.
3133
*
3234
* @param object the object [File or URL or InputStream ]
3335
*
3436
* @throws StreamPlayerException the stream player exception
37+
* @deprecated Use one of {@link #open(File)}, {@link #open(URL)} or {@link #open(InputStream)} instead.
3538
*/
39+
@Deprecated
3640
void open(Object object) throws StreamPlayerException;
3741

42+
/**
43+
* Open the specified file for playback.
44+
*
45+
* @param file the file to be played
46+
*
47+
* @throws StreamPlayerException the stream player exception
48+
*/
49+
void open(File file) throws StreamPlayerException;
50+
51+
/**
52+
* Open the specified location for playback.
53+
*
54+
* @param url the location to be played
55+
*
56+
* @throws StreamPlayerException the stream player exception
57+
*/
58+
void open(URL url) throws StreamPlayerException;
59+
60+
/**
61+
* Open the specified stream for playback.
62+
*
63+
* @param stream the stream to be played
64+
*
65+
* @throws StreamPlayerException the stream player exception
66+
*/
67+
void open(InputStream stream) throws StreamPlayerException;
68+
3869
/**
3970
* Change the Speed Rate of the Audio , this variable affects the Sample Rate ,
4071
* for example 1.0 is normal , 0.5 is half the speed and 2.0 is double the speed

src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerMethodsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ void unknown() {
324324

325325
@Test
326326
void open() throws StreamPlayerException {
327-
player.open(null);
327+
File file = null;
328+
player.open(file);
328329

329330
fail("Test not done");
330331
}

0 commit comments

Comments
 (0)