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
205 changes: 103 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Java-stream-player
Java Audio Controller Library with (seek,start,stop,pause,play,restart features)

This is a continuation and full improvement of [JavaZoom BasicPlayer](http://www.javazoom.net/jlgui/api.html)

[![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.

Expand All @@ -33,26 +32,6 @@ https://jitpack.io/private#goxr3plus/java-stream-player
</dependency>
```

## Java Audio Tutorials and API's by GOXR3PLUS STUDIO
- **Spectrum Analyzers**
- [Java-Audio-Wave-Spectrum-API](https://github.com/goxr3plus/Java-Audio-Wave-Spectrum-API)
![image](https://github.com/goxr3plus/Java-Audio-Wave-Spectrum-API/raw/master/images/Screenshot_2.jpg?raw=true)
- [Jave Spectrum Analyzers from Audio](https://github.com/goxr3plus/Java-Spectrum-Analyser-Tutorials)
- [Capture Audio from Microphone and make complex spectrum analyzers](https://github.com/goxr3plus/Java-Microphone-Audio-Spectrum-Analyzers-Tutorial)

- **Java multiple audio formats player**
- [Java-stream-player](https://github.com/goxr3plus/java-stream-player)

- **Speech Recognition/Translation/Synthenizers**
- [Java Speech Recognition/Translation/Synthesizer based on Google Cloud Services](https://github.com/goxr3plus/java-google-speech-api)
- [Java-Speech-Recognizer-Tutorial--Calculator](https://github.com/goxr3plus/Java-Speech-Recognizer-Tutorial--Calculator)
- [Java+MaryTTS=Java Text To Speech](https://github.com/goxr3plus/Java-Text-To-Speech-Tutorial)
- [Java Speech Recognition Program based on Google Cloud Services ](https://github.com/goxr3plus/Java-Google-Speech-Recognizer)
- [Java Google Text To Speech](https://github.com/goxr3plus/Java-Google-Text-To-Speech)
- [Full Google Translate Support using Java](https://github.com/goxr3plus/java-google-translator)
- [Professional Java Google Desktop Translator](https://github.com/goxr3plus/Java-Google-Desktop-Translator)


Example usage :

``` JAVA
Expand All @@ -71,123 +50,145 @@ import com.goxr3plus.streamplayer.stream.StreamPlayerException;
*/
public class Main extends StreamPlayer implements StreamPlayerListener {

private final String audioAbsolutePath = "Logic - Ballin [Bass Boosted].mp3";

/**
* Constructor
*/
public Main() {

try {
private final String audioAbsolutePath = "Logic - Ballin [Bass Boosted].mp3";

// Register to the Listeners
addStreamPlayerListener(this);
/**
* Constructor
*/
public Main() {

// Open a File
// open(new File("...")) //..Here must be the file absolute path
// open(INPUTSTREAM)
// open(AUDIOURL)
try {

// Example
open(new File(audioAbsolutePath));
// Register to the Listeners
addStreamPlayerListener(this);

//Seek by bytes
//seekBytes(500000L);
// Open a File
// open(new File("...")) //..Here must be the file absolute path
// open(INPUTSTREAM)
// open(AUDIOURL)

//Seek +x seconds starting from the current position
seekSeconds(15);
seekSeconds(15);
// Example
open(new File(audioAbsolutePath));

/* Seek starting from the begginning of the audio */
//seekTo(200);
// Seek by bytes
// seekBytes(500000L);

// Play it
play();
//pause();
// Seek +x seconds starting from the current position
seekSeconds(15);
seekSeconds(15);

} catch (final Exception ex) {
ex.printStackTrace();
}
/* Seek starting from the begginning of the audio */
// seekTo(200);

}
// Play it
play();
// pause();

@Override
public void opened(final Object dataSource, final Map<String, Object> properties) {
} catch (final Exception ex) {
ex.printStackTrace();
}

}
}

@Override
public void progress(final int nEncodedBytes, final long microsecondPosition, final byte[] pcmData,final Map<String, Object> properties) {
@Override
public void opened(final Object dataSource, final Map<String, Object> properties) {

// System.out.println("Encoded Bytes : " + nEncodedBytes);
}

// Current time position in seconds:) by GOXR3PLUS STUDIO
// This is not the more precise way ...
// in XR3Player i am using different techniques .
//https://github.com/goxr3plus/XR3Player
// Just for demostration purposes :)
// I will add more advanced techniques with milliseconds , microseconds , hours
// and minutes soon
@Override
public void progress(final int nEncodedBytes, final long microsecondPosition, final byte[] pcmData,
final Map<String, Object> properties) {

// .MP3 OR .WAV
final String extension = "mp3"; //THE SAMPLE Audio i am using is .MP3 SO ... :)
// System.out.println("Encoded Bytes : " + nEncodedBytes);

long totalBytes = getTotalBytes();
if ("mp3".equals(extension) || "wav".equals(extension)) {
// Current time position in seconds:) by GOXR3PLUS STUDIO
// This is not the more precise way ...
// in XR3Player i am using different techniques .
// https://github.com/goxr3plus/XR3Player
// Just for demostration purposes :)
// I will add more advanced techniques with milliseconds , microseconds , hours
// and minutes soon

// Calculate the progress until now
double progress = (nEncodedBytes > 0 && totalBytes > 0)
? (nEncodedBytes * 1.0f / totalBytes * 1.0f)
: -1.0f;
// System.out.println(progress*100+"%");
// .MP3 OR .WAV
final String extension = "mp3"; // THE SAMPLE Audio i am using is .MP3 SO ... :)

System.out.println("Seconds : " + (int) (microsecondPosition / 1000000) + " s " + "Progress: [ " + progress * 100 + " ] %");
long totalBytes = getTotalBytes();
if ("mp3".equals(extension) || "wav".equals(extension)) {

// Calculate the progress until now
double progress = (nEncodedBytes > 0 && totalBytes > 0) ? (nEncodedBytes * 1.0f / totalBytes * 1.0f)
: -1.0f;
// System.out.println(progress*100+"%");

// .WHATEVER MUSIC FILE*
} else {
//System.out.println("Current time is : " + (int) (microsecondPosition / 1000000) + " seconds");
}
System.out.println("Seconds : " + (int) (microsecondPosition / 1000000) + " s " + "Progress: [ "
+ progress * 100 + " ] %");

// .WHATEVER MUSIC FILE*
} else {
// System.out.println("Current time is : " + (int) (microsecondPosition /
// 1000000) + " seconds");
}

}
}

@Override
public void statusUpdated(final StreamPlayerEvent streamPlayerEvent) {
@Override
public void statusUpdated(final StreamPlayerEvent streamPlayerEvent) {

// Player status
final Status status = streamPlayerEvent.getPlayerStatus();
//System.out.println(streamPlayerEvent.getPlayerStatus());
// Player status
final Status status = streamPlayerEvent.getPlayerStatus();
// System.out.println(streamPlayerEvent.getPlayerStatus());

//Examples
// Examples

if (status == Status.OPENED) {
if (status == Status.OPENED) {

} else if (status == Status.OPENING) {
} else if (status == Status.OPENING) {

} else if (status == Status.RESUMED) {
} else if (status == Status.RESUMED) {

} else if (status == Status.PLAYING) {
} else if (status == Status.PLAYING) {

} else if (status == Status.STOPPED) {
} else if (status == Status.STOPPED) {

} else if (status == Status.SEEKING) {
} else if (status == Status.SEEKING) {

} else if (status == Status.SEEKED) {
} else if (status == Status.SEEKED) {

}
}

//etc... SEE XR3PLAYER https://github.com/goxr3plus/XR3Player for advanced examples
}
// etc... SEE XR3PLAYER https://github.com/goxr3plus/XR3Player for advanced
// examples
}

public static void main(final String[] args) {
new Main();
}
public static void main(final String[] args) {
new Main();
}

}
```


## Java Audio Tutorials and API's by GOXR3PLUS STUDIO
- **Spectrum Analyzers**
- [Java-Audio-Wave-Spectrum-API](https://github.com/goxr3plus/Java-Audio-Wave-Spectrum-API)
![image](https://github.com/goxr3plus/Java-Audio-Wave-Spectrum-API/raw/master/images/Screenshot_2.jpg?raw=true)
- [Jave Spectrum Analyzers from Audio](https://github.com/goxr3plus/Java-Spectrum-Analyser-Tutorials)
- [Capture Audio from Microphone and make complex spectrum analyzers](https://github.com/goxr3plus/Java-Microphone-Audio-Spectrum-Analyzers-Tutorial)

- **Java multiple audio formats player**
- [Java-stream-player](https://github.com/goxr3plus/java-stream-player)

- **Speech Recognition/Translation/Synthenizers**
- [Java Speech Recognition/Translation/Synthesizer based on Google Cloud Services](https://github.com/goxr3plus/java-google-speech-api)
- [Java-Speech-Recognizer-Tutorial--Calculator](https://github.com/goxr3plus/Java-Speech-Recognizer-Tutorial--Calculator)
- [Java+MaryTTS=Java Text To Speech](https://github.com/goxr3plus/Java-Text-To-Speech-Tutorial)
- [Java Speech Recognition Program based on Google Cloud Services ](https://github.com/goxr3plus/Java-Google-Speech-Recognizer)
- [Java Google Text To Speech](https://github.com/goxr3plus/Java-Google-Text-To-Speech)
- [Full Google Translate Support using Java](https://github.com/goxr3plus/java-google-translator)
- [Professional Java Google Desktop Translator](https://github.com/goxr3plus/Java-Google-Desktop-Translator)



---

### Looking for a ffmpeg wrapper in Java ?
Expand Down
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.goxr3plus</groupId>
Expand All @@ -13,7 +13,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.5.1</junit.version>
<junit.version>5.1.1</junit.version>
</properties>

<build>
Expand Down Expand Up @@ -165,6 +165,13 @@
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>


</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.goxr3plus.streamplayer.application;

import com.goxr3plus.streamplayer.enums.Status;
import com.goxr3plus.streamplayer.stream.StreamPlayer;
import com.goxr3plus.streamplayer.stream.StreamPlayerEvent;
import com.goxr3plus.streamplayer.stream.StreamPlayerListener;

import java.io.File;
import java.util.Map;

/**
* @author GOXR3PLUS
*
*/
public class AnotherDemoApplication {

private final String audioFileName = "Logic - Ballin [Bass Boosted].mp3";

private StreamPlayer streamPlayer;
private StreamPlayerListener listener;

public AnotherDemoApplication(StreamPlayer streamPlayer) {
this.streamPlayer = streamPlayer;
this.listener = new AnotherStreamPlayerListener(audioFileName, streamPlayer);

}


void start() {
try {

// Register to the Listeners
streamPlayer.addStreamPlayerListener(listener);

// Open a File
// open(new File("...")) //..Here must be the file absolute path
// open(INPUTSTREAM)
// open(AUDIOURL)

// Example
streamPlayer.open(new File(audioFileName));

//Seek by bytes
//seekBytes(500000L);

//Seek +x seconds starting from the current position
streamPlayer.seekSeconds(15); // forward 15 seconds
streamPlayer.seekSeconds(15); // forward 15 seconds again

/* Seek starting from the begginning of the audio */
//seekTo(200);

// Play it
streamPlayer.play();
//pause();

} catch (final Exception ex) {
ex.printStackTrace();
}
}




private String getExtension(String audioFileName) {
return audioFileName.split("\\.(?=[^.]+$)")[1];
}


// public static void main(final String[] args) {
// new AnotherDemoApplication();
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.goxr3plus.streamplayer.application;

import com.goxr3plus.streamplayer.stream.StreamPlayer;
import com.goxr3plus.streamplayer.stream.StreamPlayerListener;

public class AnotherMain {
public static void main(String[] args) {

final StreamPlayer streamPlayer = new StreamPlayer();
final AnotherDemoApplication application = new AnotherDemoApplication(streamPlayer);
application.start();

}

}
Loading