Giter Site home page Giter Site logo

lavaplayer-wrapper's Introduction

LavaplayerWrapper

A simple wrapper around the Lavaplayer library that implements various Javacord audio sources.

The goal of the project is to provide Javacord audio sources by wrapping the Lavaplayer library. This is only a temporary solution and we are going to create a lightweight audio sources repository that is independent of Lavaplayer once Javacord's audio api get's released and is fully usable. At the moment, the focus is on making Javacord's audio stable and ready for release.

Disclaimer

This repository is using Bastian's Javacord fork which adds audio support to Javacord. It is still in development and can introduce breaking changes at any time. Once it will be merged into the official Javacord repository, this repository will be updated to use the official audio api.

Download

This repository is currently only available through Jitpack. Future version will be published to Maven Central.

repositories {
    jcenter()
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation group: 'com.github.Bastian', name: 'Lavaplayer-Wrapper', version: 'master-SNAPSHOT'
}

For best compatibility, do not include Javacord or Lavaplayer but use the one that ships with this dependency.

Supported audio sources

LavaplayerAudioSource

An audio source that uses Lavaplayer's AudioPlayer to provide audio. While this is the most flexible audio source, you exclusively work with Lavaplayer's api which technically is exactly the opposite of what this library tries to archive. You should only use it as a fallback for Lavaplayer features that are not yet covered by this library. Otherwise you can just directly use the Lavaplayer library.

DiscordApi api = ...;
AudioConnection connection = ...;

// Create a player manager
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
AudioPlayer player = playerManager.createPlayer();

// Create an audio source and add it to the audio connection's queue
AudioSource source = new LavaplayerAudioSource(api, player);
connection.queue(source);

// You can now use the AudioPlayer like you would normaly do with Lavaplayer, e.g.
playerManager.loadItem(identifier, new AudioLoadResultHandler() {
    @Override
    public void trackLoaded(AudioTrack track) {
        player.play(track);
    }

    @Override
    public void playlistLoaded(AudioPlaylist playlist) {
        for (AudioTrack track : playlist.getTracks()) {
            player.play(track);
        }
    }

    @Override
    public void noMatches() {
        // Notify the user that we've got nothing
    }

    @Override
    public void loadFailed(FriendlyException throwable) {
        // Notify the user that everything exploded
    }
}

Take a look at Lavaplayer's documentation for more details.

YouTubeAudioSource

An audio source that supports playing YouTube videos.

DiscordApi api = ...;
AudioConnection connection = ...;

// Simple version
AudioSource source = YouTubeAudioSource.of(api, "https://youtu.be/NvS351QKFV4").join();
connection.queue(source);

// Advanced
AudioSource source = new YouTubeAudioSourceBuilder(api)
    .setUrl("https://youtu.be/NvS351QKFV4")
    .build()
    .thenCompose(YouTubeAudioSource::download) // Optional: Download the full song before queueing it.
    .thenAccept(connection::queue)
    .exceptionally(throwable -> {
        // Loading or downloading the youtube video failed
        return null;
    });

lavaplayer-wrapper's People

Contributors

bastian avatar mysterypotatoguy avatar

Watchers

 avatar  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.