Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove eventsExecutorService thread #50

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e023071
Update StreamPlayer.java
HelgeStenstrom Sep 24, 2019
dfd34cd
Remove unneeded thread
HelgeStenstrom Sep 24, 2019
664fa3b
Create PULL_REQUEST_TEMPLATE.md
goxr3plus Sep 25, 2019
87f0f59
Update PULL_REQUEST_TEMPLATE.md
goxr3plus Sep 25, 2019
75f289a
Update README.md
goxr3plus Nov 26, 2019
b1e1fbe
Update README.md
goxr3plus Nov 26, 2019
06b357c
Update README.md
goxr3plus Nov 26, 2019
75b9f0d
Update README.md
goxr3plus Nov 26, 2019
4164010
Update README.md
goxr3plus Nov 26, 2019
9da1581
Update README.md
goxr3plus Nov 26, 2019
fb6651f
Update README.md
goxr3plus Nov 26, 2019
987d0cd
Update README.md
goxr3plus Nov 29, 2019
6a00a79
Update README.md
goxr3plus Dec 9, 2019
719d370
minor JavaDoc and readability improvement
HelgeStenstrom Dec 18, 2019
0ef3d2f
Update StreamPlayerMethodsTest.java
HelgeStenstrom Dec 18, 2019
afb30bc
AudioSystem.getMixerInfo() will not return null, so we don't have to …
HelgeStenstrom Dec 19, 2019
68c67ca
Improved and re-structured unit tests
HelgeStenstrom Dec 20, 2019
dca8c7a
Improved and more complete unit tests.
HelgeStenstrom Dec 22, 2019
2905d6e
Merge pull request #59 from HelgeStenstrom/improveUnitTesting
goxr3plus Dec 22, 2019
7f08cff
Merge pull request #56 from HelgeStenstrom/removeNullChecks
goxr3plus Dec 31, 2019
8463821
Update README.md
goxr3plus Jan 1, 2020
074a81b
Update README.md
goxr3plus Feb 27, 2020
1ec869b
Update pom.xml
goxr3plus Mar 31, 2020
b1af6cb
Update StreamPlayer.java
HelgeStenstrom Sep 24, 2019
439b433
Remove unneeded thread
HelgeStenstrom Sep 24, 2019
a742e0e
Merge branch 'RemoveEventThread' of https://github.com/HelgeStenstrom…
HelgeStenstrom Mar 31, 2020
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
44 changes: 44 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Description

Please include a summary of the change and which issue is fixed.
List any dependencies that are required for this change.

<!--
Please make sure to read the Pull Request Guidelines:
https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#pull-request-guidelines
-->

<!-- PULL REQUEST TEMPLATE -->
<!-- (Update "[ ]" to "[x]" to check a box) -->

**What kind of change does this PR introduce?** (check at least one)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Code style update
- [ ] Refactor
- [ ] Build-related changes
- [ ] This change requires a documentation update
- [ ] Other, please describe:

**Does this PR introduce a breaking change?** (check one)

- [ ] Yes
- [ ] No

# Has This Been Tested?

- [ ] Yes
- [ ] No

# Checklist:

- [X] My code follows the style guidelines of this project
- [X] I have performed a self-review of my own code
- [X] I have commented my code, particularly in hard-to-understand areas
- [X] I have made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [X] I have added tests that prove my fix is effective or that my feature works
- [X] New and existing unit tests pass locally with my changes
- [X] Any dependent changes have been merged and published in downstream modules
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
### [![AlexKent](https://user-images.githubusercontent.com/20374208/75432997-f5422100-5957-11ea-87a2-164eb98d83ef.png)](https://www.minepi.com/AlexKent) Support me joining PI Network app with invitation code [AlexKent](https://www.minepi.com/AlexKent) [![AlexKent](https://user-images.githubusercontent.com/20374208/75432997-f5422100-5957-11ea-87a2-164eb98d83ef.png)](https://www.minepi.com/AlexKent)

---

<h3 align="center" > Java Stream Player ( Library )</h3>
<p align="center">
🎶
</p>
<p align="center">
<sup>
<b>Java Audio Controller Library with (skip,skipTo,start,stop,pause,play,restart) </b>
<b> This is the next version of <a href="http://www.javazoom.net/jlgui/api.html" target="_blank">JavaZoom BasicPlayer</a> </b>
</sup>
</p>

---

[![Latest Version](https://img.shields.io/github/release/goxr3plus/java-stream-player.svg?style=flat-square)](https://github.com/goxr3plus/java-stream-player/releases)
[![HitCount](http://hits.dwyl.io/goxr3plus/java-stream-player.svg)](http://hits.dwyl.io/goxr3plus/java-stream-player)
<a href="https://patreon.com/preview/8adae1b75d654b2899e04a9e1111f0eb" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a>
<a href="https://www.paypal.me/GOXR3PLUSCOMPANY" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-yellow.svg" alt="PayPal donate button" /></a>


# Java-stream-player
Java Audio Controller Library with (skip,skipTo,start,stop,pause,play,restart features)
This is the next version of [JavaZoom BasicPlayer](http://www.javazoom.net/jlgui/api.html)

### What audio formats it supports?
It supports **WAV, AU, AIFF, MP3, OGG VORBIS, FLAC, MONKEY's AUDIO and SPEEX audio formats** , using some external libraries . Although more will be added in future releases.


### Step 1. Add the JitPack repository to your build file
- **Fully Supported ✔️**
- WAV
- MP3
- **Partially not full tested 🚧**
- OGG VORBIS
- FLAC
- MONKEY's AUDIO
- SPEEX
- **Not Supported Yet ❌**
- AAC
- THEORA
- ... all the others


### Step 1. Add the JitPack repository to your build file
https://jitpack.io/private#goxr3plus/java-stream-player
``` XML
<repositories>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.goxr3plus</groupId>
<artifactId>java-stream-player</artifactId>
<version>9.0.5</version>
<version>10.0.0</version>


<properties>
Expand Down
63 changes: 24 additions & 39 deletions src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
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;
Expand Down Expand Up @@ -120,11 +115,6 @@ public class StreamPlayer implements StreamPlayerInterface, Callable<Void> {
private final ExecutorService streamPlayerExecutorService;
private Future<Void> future;

/**
* This executor service is used in order the playerState events to be executed
* in an order
*/
private final ExecutorService eventsExecutorService;

/** Holds a list of Linteners to be notified about Stream PlayerEvents */
private final ArrayList<StreamPlayerListener> listeners;
Expand Down Expand Up @@ -154,20 +144,17 @@ public StreamPlayer() {
*/
public StreamPlayer(Logger logger) {
this(logger,
Executors.newSingleThreadExecutor(new ThreadFactoryWithNamePrefix("StreamPlayer")),
Executors.newSingleThreadExecutor(new ThreadFactoryWithNamePrefix("StreamPlayerEvent")));
Executors.newSingleThreadExecutor(new ThreadFactoryWithNamePrefix("StreamPlayer")));
}

/**
* Constructor with settable logger and executor services.
* @param logger The logger that will be used by the player
* @param streamPlayerExecutorService Executor service for the stream player
* @param eventsExecutorService Executor service for events.
*/
public StreamPlayer(Logger logger, ExecutorService streamPlayerExecutorService, ExecutorService eventsExecutorService) {
public StreamPlayer(Logger logger, ExecutorService streamPlayerExecutorService) {
this.logger = logger;
this.streamPlayerExecutorService = streamPlayerExecutorService;
this.eventsExecutorService = eventsExecutorService;
listeners = new ArrayList<>();
outlet = new Outlet(logger);
reset();
Expand Down Expand Up @@ -210,17 +197,10 @@ public void reset() {
* @param encodedStreamPosition in the stream when the event occurs.
* @param description the description
*
* @return A String Describing if any problem occurred
*/
private String generateEvent(final Status status, final int encodedStreamPosition, final Object description) {
try {
return eventsExecutorService
.submit(new StreamPlayerEventLauncher(this, status, encodedStreamPosition, description, listeners))
.get();
} catch (InterruptedException | ExecutionException ex) {
logger.log(Level.WARNING, "Problem in StreamPlayer generateEvent() method", ex);
}
return "Problem in StreamPlayer generateEvent() method";
private void generateEvent(final Status status, final int encodedStreamPosition, final Object description) {
new StreamPlayerEventLauncher(this, status, encodedStreamPosition, description, listeners).call();

}

/**
Expand Down Expand Up @@ -574,7 +554,7 @@ public void play() throws StreamPlayerException {

// Proceed only if we have not problems
logger.info("Submitting new StreamPlayer Thread");
streamPlayerExecutorService.submit(this);
Future<Void> submit = streamPlayerExecutorService.submit(this);

// Update the status
status = Status.PLAYING;
Expand Down Expand Up @@ -994,17 +974,16 @@ public List<String> getMixers() {
// audio mixers that are currently installed on the system.
final Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();

if (mixerInfos != null)
Arrays.stream(mixerInfos).forEach(mInfo -> {
// line info
final Line.Info lineInfo = new Line.Info(SourceDataLine.class);
final Mixer mixer = AudioSystem.getMixer(mInfo);
Arrays.stream(mixerInfos).forEach(mInfo -> {
// line info
final Line.Info lineInfo = new Line.Info(SourceDataLine.class);
final Mixer mixer = AudioSystem.getMixer(mInfo);

// if line supported
if (mixer.isLineSupported(lineInfo))
mixers.add(mInfo.getName());
// if line supported
if (mixer.isLineSupported(lineInfo))
mixers.add(mInfo.getName());

});
});

return mixers;
}
Expand All @@ -1023,7 +1002,7 @@ private Mixer getMixer(final String name) {
// audio mixers that are currently installed on the system.
final Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();

if (name != null && mixerInfos != null)
if (name != null)
for (Mixer.Info mixerInfo : mixerInfos)
if (mixerInfo.getName().equals(name)) {
mixer = AudioSystem.getMixer(mixerInfo);
Expand Down Expand Up @@ -1067,12 +1046,18 @@ public float getMinimumGain() {

/**
* Returns Pan precision.
* <p>
* Obtains the resolution or granularity of the control, in the units that the control measures.
* The precision is the size of the increment between discrete valid values for this control,
* over the set of supported floating-point values.
*
* @return The Precision Value
* @return The Precision Value for the pan control, if it exists, otherwise 0.0.
*/
@Override
public float getPrecision() {
return !outlet.hasControl(FloatControl.Type.PAN, outlet.getPanControl()) ? 0.0F : outlet.getPanControl().getPrecision();
return !outlet.hasControl(FloatControl.Type.PAN, outlet.getPanControl())
? 0
: outlet.getPanControl().getPrecision();

}

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

import com.goxr3plus.streamplayer.enums.Status;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

/**
* Tests of all or most of the public methods of StreamPlayer.
* These unit tests are written primarily as documentation of the behavior and as example use case,
* not as a part of test driven development.
*/
public class StreamPlayerFutureImprovementTest {
StreamPlayer player;
private File audioFile;

@BeforeEach
void setup() {
final Logger logger = mock(Logger.class);
player = new StreamPlayer(logger);
audioFile = new File("Logic - Ballin [Bass Boosted].mp3");
}

/**
* This test fails if it's permitted to add a null to the StreamPlayer listener list.
*/
@Test
void addStreamPlayerListener_dontAcceptNull() {
// Currently, we can add a null to the list of stream player listeners.
// Should that really be allowed?
assertThrows(Exception.class, () -> player.addStreamPlayerListener(null));

fail("Test not done");
}


@Test
@DisplayName("When play() is called without first calling open(), an exception is thrown")
void playingUnopenedSourceThrowsException() {

assertThrows(Exception.class, () -> player.play());
}

@Test
void seekBytes() throws StreamPlayerException {
player.open(audioFile);
player.play();
int positionByte1 = player.getPositionByte();

player.seekBytes(100);
int positionByte2 = player.getPositionByte();

assertTrue( positionByte2 > positionByte1);

// TODO: It seems that getPositionByte doesn't work.
// It isn't called from within this project, except for in this test.
// It is however called by XR3Player. If XR3Player needs this method, it must be tested
// within this project. The method relies on a map, which doesn't seem to be updated by play()
}

}
Loading