Skip to content
Open
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
16 changes: 0 additions & 16 deletions src/main/java/com/goxr3plus/streamplayer/stream/DataSource.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
package com.goxr3plus.streamplayer.stream;

import javax.naming.OperationNotSupportedException;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.time.Duration;

public interface DataSource {
static DataSource newDataSource(Object source) throws OperationNotSupportedException {
if (source instanceof File) {
return new FileDataSource((File) source);
}
if (source instanceof URL) {
return new UrlDataSource((URL) source);
}
if (source instanceof InputStream) {
return new StreamDataSource((InputStream) source);
}
throw new OperationNotSupportedException();
}

Object getSource(); // TODO: Try to make this method not needed.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.goxr3plus.streamplayer.stream;

import javax.naming.OperationNotSupportedException;
import java.io.File;
import java.io.InputStream;
import java.net.URL;

public class DataSourceFactory {

private DataSourceFactory() {}

public static DataSource newDataSource(Object source) throws OperationNotSupportedException {
if (source instanceof File) {
return new FileDataSource((File) source);
}
if (source instanceof URL) {
return new UrlDataSource((URL) source);
}
if (source instanceof InputStream) {
return new StreamDataSource((InputStream) source);
}
throw new OperationNotSupportedException();
}
}
45 changes: 11 additions & 34 deletions src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,26 @@

package com.goxr3plus.streamplayer.stream;

import com.goxr3plus.streamplayer.enums.Status;
import com.goxr3plus.streamplayer.stream.StreamPlayerException.PlayerException;
import javazoom.spi.PropertiesContainer;
import org.tritonus.share.sampled.TAudioFormat;
import org.tritonus.share.sampled.file.TAudioFileFormat;

import javax.naming.OperationNotSupportedException;
import javax.sound.sampled.*;
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.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.naming.OperationNotSupportedException;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.BooleanControl;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;

import org.tritonus.share.sampled.TAudioFormat;
import org.tritonus.share.sampled.file.TAudioFileFormat;

import com.goxr3plus.streamplayer.enums.Status;
import com.goxr3plus.streamplayer.stream.StreamPlayerException.PlayerException;

import javazoom.spi.PropertiesContainer;

/**
* StreamPlayer is a class based on JavaSound API. It has been successfully tested under Java 10
*
Expand Down Expand Up @@ -275,7 +252,7 @@ public void open(final Object object) throws StreamPlayerException {
return;

try {
source = DataSource.newDataSource(object);
source = DataSourceFactory.newDataSource(object);
} catch (OperationNotSupportedException e) {
e.printStackTrace();
}
Expand Down