GithubHelp home page GithubHelp logo

lang5200 / java-stream-player Goto Github PK

View Code? Open in Web Editor NEW

This project forked from goxr3plus/java-stream-player

1.0 0.0 0.0 5.53 MB

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

License: GNU General Public License v3.0

Java 100.00%

java-stream-player's Introduction

AlexKent Support me joining PI Network app with invitation code AlexKent AlexKent


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 Version HitCount Patreon donate button PayPal 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 :

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

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

/**
 * @author GOXR3PLUS
 *
 */
public class Main extends StreamPlayer implements StreamPlayerListener {

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

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

        try {

            // Register to the Listeners
            addStreamPlayerListener(this);

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

            // Example
            open(new File(audioAbsolutePath));

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

            // Seek +x seconds starting from the current position
            seekSeconds(15);
            seekSeconds(15);

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

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

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

    }

    @Override
    public void opened(final Object dataSource, final Map<String, Object> properties) {

    }

    @Override
    public void progress(final int nEncodedBytes, final long microsecondPosition, final byte[] pcmData,
            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

        // .MP3 OR .WAV
        final String extension = "mp3"; // THE SAMPLE Audio i am using is .MP3 SO ... :)

        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+"%");

            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) {

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

        // Examples

        if (status == Status.OPENED) {

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

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

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

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

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

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

        }

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

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

}

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

java-stream-player's People

Contributors

goxr3plus avatar helgestenstrom avatar tonalidadehidrica avatar jellevanabbema avatar aobuchow avatar dependabot[bot] avatar

Stargazers

Lang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.