diff --git a/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java b/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java index fbe5835..6279c9a 100644 --- a/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java +++ b/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java @@ -10,6 +10,14 @@ 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; @@ -31,28 +39,6 @@ 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 * @@ -223,7 +209,7 @@ public void reset() { private String generateEvent(final Status status, final int encodedStreamPosition, final Object description) { try { return eventsExecutorService - .submit(new StreamPlayerEventLauncher(this, status, encodedStreamPosition, description, listeners)) + .submit(new StreamPlayerEventLauncher(this, status, encodedStreamPosition, description, listeners, logger)) .get(); } catch (InterruptedException | ExecutionException ex) { logger.log(Level.WARNING, "Problem in StreamPlayer generateEvent() method", ex); @@ -1412,10 +1398,6 @@ public boolean isSeeking() { return status == Status.SEEKING; } - Logger getLogger() { - return logger; - } - @Override public SourceDataLine getSourceDataLine() { return outlet.getSourceDataLine(); diff --git a/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerEvent.java b/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerEvent.java index 23cc13a..7f8af9c 100644 --- a/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerEvent.java +++ b/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerEvent.java @@ -37,17 +37,12 @@ public class StreamPlayerEvent { /** The stream position. */ private int encodedStreamPosition = -1; - /** The source. */ - private StreamPlayer source = null; - /** The description. */ private Object description = null; /** * Constructor. * - * @param source - * the source * @param status * the status * @param encodededStreamPosition @@ -55,9 +50,8 @@ public class StreamPlayerEvent { * @param description * the description */ - public StreamPlayerEvent(StreamPlayer source, Status status, int encodededStreamPosition, Object description) { - this.source = source; - this.playerStatus = status; + public StreamPlayerEvent(Status status, int encodededStreamPosition, Object description) { + this.playerStatus = status; this.encodedStreamPosition = encodededStreamPosition; this.description = description; } @@ -91,18 +85,9 @@ public Object getDescription() { return description; } - /** - * Gets the source. - * - * @return the source - */ - public Object getSource() { - return source; - } - @Override public String toString() { - return "Source :=" + source + " , Player Status := " + playerStatus + " , EncodedStreamPosition :=" + return "Player Status := " + playerStatus + " , EncodedStreamPosition :=" + encodedStreamPosition + " , Description :=" + description; } diff --git a/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventLauncher.java b/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventLauncher.java index 34d32f0..5dbc5f0 100644 --- a/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventLauncher.java +++ b/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventLauncher.java @@ -22,13 +22,13 @@ */ package com.goxr3plus.streamplayer.stream; +import com.goxr3plus.streamplayer.enums.Status; + import java.util.List; import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.logging.Logger; -import com.goxr3plus.streamplayer.enums.Status; - /** * The Class StreamPlayerEventLauncher. * @@ -50,29 +50,26 @@ public class StreamPlayerEventLauncher implements Callable { private List listeners = null; /** The source. */ - private StreamPlayer source = null; + private StreamPlayerInterface source = null; /** * Instantiates a new stream player event launcher. - * - * @param source - * the source - * @param playerStatus - * the play state - * @param encodedStreamPosition - * the stream position - * @param description - * the description - * @param listeners + * + * @param source the source + * @param playerStatus the play state + * @param encodedStreamPosition the stream position + * @param description the description + * @param listeners will be called when events happens + * @param logger Logger to use for logging */ - public StreamPlayerEventLauncher(StreamPlayer source, Status playerStatus, int encodedStreamPosition, Object description, - List listeners) { + public StreamPlayerEventLauncher(StreamPlayerInterface source, Status playerStatus, int encodedStreamPosition, Object description, + List listeners, Logger logger) { this.source = source; this.playerState = playerStatus; this.encodedStreamPosition = encodedStreamPosition; this.description = description; this.listeners = listeners; - this.logger = source.getLogger(); + this.logger = logger; } @Override @@ -80,7 +77,7 @@ public String call() { // Notify all the listeners that the state has been updated if (listeners != null) { listeners.forEach(listener -> listener - .statusUpdated(new StreamPlayerEvent(source, playerState, encodedStreamPosition, description))); + .statusUpdated(new StreamPlayerEvent(playerState, encodedStreamPosition, description))); } logger.log(Level.INFO, "Stream player Status -> " + playerState); return "OK"; diff --git a/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventTest.java b/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventTest.java index d8ed334..5e7ebb3 100644 --- a/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventTest.java +++ b/src/test/java/com/goxr3plus/streamplayer/stream/StreamPlayerEventTest.java @@ -3,26 +3,23 @@ import com.goxr3plus.streamplayer.enums.Status; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.configuration.IMockitoConfiguration; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; class StreamPlayerEventTest { - private StreamPlayer source; private Object description; private Status status; - private int encodededStreamPosition; + private int encodedStreamPosition; private StreamPlayerEvent event; @BeforeEach void setUp() { description = new Object(); - source = mock(StreamPlayer.class); status = Status.RESUMED; - encodededStreamPosition = 12345; - event = new StreamPlayerEvent(source, status, encodededStreamPosition, description); + encodedStreamPosition = 12345; + event = new StreamPlayerEvent(status, encodedStreamPosition, description); } @Test @@ -32,12 +29,7 @@ void itReturnsTheStatus() { @Test void itReturnsTheEncodedStreamPosition() { - assertEquals(encodededStreamPosition, event.getEncodedStreamPosition()); - } - - @Test - void itReturnsTheSource() { - assertSame(source, event.getSource()); + assertEquals(encodedStreamPosition, event.getEncodedStreamPosition()); } @Test @@ -48,12 +40,8 @@ void itReturnsTheDescription() { @Test void itReturnsAString() { final String actual = event.toString(); - final String expected = "Source :=" - + source.toString() - + " , Player Status := RESUMED , EncodedStreamPosition :=12345 , Description :=" + final String expected = "Player Status := RESUMED , EncodedStreamPosition :=12345 , Description :=" + description.toString(); assertEquals(expected, actual); } - - } \ No newline at end of file