Skip to content

Repository files navigation

ko-fi


Java Stream Player ( Library )

🎶

Java Audio Controller Library with (skip,skipTo,start,stop,pause,play,restart) This is the next version of JavaZoom BasicPlayer


Latest VersionHitCountPatreon donate buttonPayPal donate button

What audio formats it supports?

  • 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

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Step 2. Add the dependency

<dependency>
<groupId>com.github.goxr3plus</groupId>
<artifactId>java-stream-player</artifactId>
<version>9.0.4</version>
</dependency>

Example usage :

importjava.io.File;
importjava.util.Map;
importcom.goxr3plus.streamplayer.enums.Status;
importcom.goxr3plus.streamplayer.stream.StreamPlayer;
importcom.goxr3plus.streamplayer.stream.StreamPlayerListener;
importcom.goxr3plus.streamplayer.stream.StreamPlayerEvent;
importcom.goxr3plus.streamplayer.stream.StreamPlayerException;
/** * @author GOXR3PLUS * */publicclassMainextendsStreamPlayerimplementsStreamPlayerListener {
privatefinalStringaudioAbsolutePath = "Logic - Ballin [Bass Boosted].mp3";
/** * Constructor */publicMain() {
try {
// Register to the ListenersaddStreamPlayerListener(this);
// Open a File// open(new File("...")) //..Here must be the file absolute path// open(INPUTSTREAM)// open(AUDIOURL)// Exampleopen(newFile(audioAbsolutePath));
// Seek by bytes// seekBytes(500000L);// Seek +x seconds starting from the current positionseekSeconds(15);
seekSeconds(15);
/* Seek starting from the begginning of the audio */// seekTo(200);// Play itplay();
// pause();
} catch (finalExceptionex) {
ex.printStackTrace();
}
}
@Overridepublicvoidopened(finalObjectdataSource, finalMap<String, Object> properties) {
}
@Overridepublicvoidprogress(finalintnEncodedBytes, finallongmicrosecondPosition, finalbyte[] pcmData,
finalMap<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// .MP3 OR .WAVfinalStringextension = "mp3"; // THE SAMPLE Audio i am using is .MP3 SO ... :)longtotalBytes = getTotalBytes();
if ("mp3".equals(extension) || "wav".equals(extension)) {
// Calculate the progress until nowdoubleprogress = (nEncodedBytes > 0 && totalBytes > 0) ? (nEncodedBytes * 1.0f / totalBytes * 1.0f)
: -1.0f;
// System.out.println(progress*100+"%");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");
}
}
@OverridepublicvoidstatusUpdated(finalStreamPlayerEventstreamPlayerEvent) {
// Player statusfinalStatusstatus = streamPlayerEvent.getPlayerStatus();
// System.out.println(streamPlayerEvent.getPlayerStatus());// Examplesif (status == Status.OPENED) {
} elseif (status == Status.OPENING) {
} elseif (status == Status.RESUMED) {
} elseif (status == Status.PLAYING) {
} elseif (status == Status.STOPPED) {
} elseif (status == Status.SEEKING) {
} elseif (status == Status.SEEKED) {
}
// etc... SEE XR3PLAYER https://github.com/goxr3plus/XR3Player for advanced// examples
}
publicstaticvoidmain(finalString[] args) {
newMain();
}
}

Java Audio Tutorials and API's by GOXR3PLUS STUDIO


Looking for a ffmpeg wrapper in Java ?

Check this -> jave2 , currently updating it :)


Originally being developed for XR3Player Application

Are you curious on how to make spectrum analysers in Java? Well the below tutorials plus the above code are the solution :)

I hope you enjoy these tutorials and actually you can watch the youtube videos about them below:

Java Spectrum Analyser Tutorial

About

🌌Java Advanced Audio Controller Library (WAV, AU, AIFF, MP3, OGG VORBIS, FLAC, MONKEY's AUDIO and SPEEX audio formats )

Topics

Resources

Stars

158 stars

Watchers

9 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages