Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
Expand Down Expand Up @@ -248,15 +251,17 @@ public void removeStreamPlayerListener(final StreamPlayerListener streamPlayerLi
* @param object the object [File or URL or InputStream ]
*
* @throws StreamPlayerException the stream player exception
* @deprecated Use one of {@link #open(File)}, {@link #open(URL)} or {@link #open(InputStream)} instead.
*
*/
@Override
@Deprecated
public void open(final Object object) throws StreamPlayerException {

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

//source = new DataSource(object);
try {
source = DataSource.newDataSource(object);
} catch (OperationNotSupportedException e) {
Expand All @@ -265,6 +270,46 @@ public void open(final Object object) throws StreamPlayerException {
initAudioInputStream();
}

/**
* Open the specified file for playback.
*
* @param file the file to be played
* @throws StreamPlayerException the stream player exception
*/
@Override
public void open(File file) throws StreamPlayerException {

logger.info(() -> "open(" + file + ")\n");
source = new FileDataSource(file);
initAudioInputStream();
}

/**
* Open the specified location for playback.
*
* @param url the location to be played
* @throws StreamPlayerException the stream player exception
*/
@Override
public void open(URL url) throws StreamPlayerException {
logger.info(() -> "open(" + url + ")\n");
source = new UrlDataSource(url);
initAudioInputStream();
}

/**
* Open the specified stream for playback.
*
* @param stream the stream to be played
* @throws StreamPlayerException the stream player exception
*/
@Override
public void open(InputStream stream) throws StreamPlayerException {
logger.info(() -> "open(" + stream + ")\n");
source = new StreamDataSource(stream);
initAudioInputStream();
}

/**
* Create AudioInputStream and AudioFileFormat from the data source.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.goxr3plus.streamplayer.enums.Status;

import javax.sound.sampled.SourceDataLine;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.concurrent.Callable;

public interface StreamPlayerInterface {
/**
Expand All @@ -27,14 +29,43 @@ public interface StreamPlayerInterface {
void removeStreamPlayerListener(StreamPlayerListener streamPlayerListener);

/**
* Open the specific object which can be File,URL or InputStream.
* Open the specified object which can be File,URL or InputStream.
*
* @param object the object [File or URL or InputStream ]
*
* @throws StreamPlayerException the stream player exception
* @deprecated Use one of {@link #open(File)}, {@link #open(URL)} or {@link #open(InputStream)} instead.
*/
@Deprecated
void open(Object object) throws StreamPlayerException;

/**
* Open the specified file for playback.
*
* @param file the file to be played
*
* @throws StreamPlayerException the stream player exception
*/
void open(File file) throws StreamPlayerException;

/**
* Open the specified location for playback.
*
* @param url the location to be played
*
* @throws StreamPlayerException the stream player exception
*/
void open(URL url) throws StreamPlayerException;

/**
* Open the specified stream for playback.
*
* @param stream the stream to be played
*
* @throws StreamPlayerException the stream player exception
*/
void open(InputStream stream) throws StreamPlayerException;

/**
* Change the Speed Rate of the Audio , this variable affects the Sample Rate ,
* for example 1.0 is normal , 0.5 is half the speed and 2.0 is double the speed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ void unknown() {

@Test
void open() throws StreamPlayerException {
player.open(null);
File file = null;
player.open(file);

fail("Test not done");
}
Expand Down