com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager Java Examples
The following examples show how to use
com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestUtils.java From andesite-node with MIT License | 6 votes |
/** * Decodes an audio track from it's base64 representation. * * @param playerManager Player manager used for decoding (must have the source manager enabled). * @param base64 Base64 encoded track. * * @return The decoded track. */ @Nullable @CheckReturnValue public static AudioTrack decodeTrack(@Nonnull AudioPlayerManager playerManager, @Nonnull String base64) { try { var v = playerManager.decodeTrack(new MessageInput(new ByteArrayInputStream( Base64.getDecoder().decode(base64) ))); return v == null ? null : v.decodedTrack; } catch(IOException e) { throw new AssertionError(e); } }
Example #2
Source File: RequestUtils.java From andesite-node with MIT License | 6 votes |
/** * Encodes a track into a json object, useful for sending to clients. * * @param playerManager Player manager used to encode the track. * @param track Track to encode. * * @return A json object containing information about the track. */ @Nonnull @CheckReturnValue public static JsonObject encodeTrack(@Nonnull AudioPlayerManager playerManager, @Nonnull AudioTrack track) { var info = track.getInfo(); return new JsonObject() .put("track", trackString(playerManager, track)) .put("info", new JsonObject() .put("class", track.getClass().getName()) .put("title", info.title) .put("author", info.author) .put("length", info.length) .put("identifier", info.identifier) .put("uri", info.uri) .put("isStream", info.isStream) .put("isSeekable", track.isSeekable()) .put("position", track.getPosition()) ); }
Example #3
Source File: LocalPlayerDemo.java From lavaplayer with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws LineUnavailableException, IOException { AudioPlayerManager manager = new DefaultAudioPlayerManager(); AudioSourceManagers.registerRemoteSources(manager); manager.getConfiguration().setOutputFormat(COMMON_PCM_S16_BE); AudioPlayer player = manager.createPlayer(); manager.loadItem("ytsearch: epic soundtracks", new FunctionalResultHandler(null, playlist -> { player.playTrack(playlist.getTracks().get(0)); }, null, null)); AudioDataFormat format = manager.getConfiguration().getOutputFormat(); AudioInputStream stream = AudioPlayerInputStream.createStream(player, format, 10000L, false); SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat()); SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); line.open(stream.getFormat()); line.start(); byte[] buffer = new byte[COMMON_PCM_S16_BE.maximumChunkSize()]; int chunkSize; while ((chunkSize = stream.read(buffer)) >= 0) { line.write(buffer, 0, chunkSize); } }
Example #4
Source File: AudioUtils.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
private static void setCustomSourcesOn(AudioPlayerManager playerManager, boolean isLavalinkPlayer) { DuncteBotSources.registerCustom(playerManager, "en-AU", 1, // Update youtube data when not local // When we are dealing with a lavalink player we don't want to update everything since we are only decoding !Settings.IS_LOCAL && !isLavalinkPlayer ); }
Example #5
Source File: GuildMusicManager.java From Yui with Apache License 2.0 | 5 votes |
/** * Creates a player and a track scheduler. * @param manager Audio player manager to use for creating the player. */ public GuildMusicManager(AudioPlayerManager manager) { player = manager.createPlayer(); scheduler = new TrackScheduler(player); sendHandler = new AudioPlayerSendHandler(player); player.addListener(scheduler); }
Example #6
Source File: LavalinkTrackLoader.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
private static AudioTrack decode(AudioPlayerManager manager, String track) { try { return manager.decodeTrack(new MessageInput(new ByteArrayInputStream( Base64.getDecoder().decode(track) ))).decodedTrack; } catch (Exception e) { throw new IllegalArgumentException("Failed to decode track", e); } }
Example #7
Source File: LavalinkTrackLoader.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
public static void load(AudioPlayerManager manager, Lavalink<?> lavalink, String query, AudioLoadResultHandler handler) { Iterator<LavalinkSocket> sockets = lavalink.getNodes().iterator(); if (!sockets.hasNext()) { manager.loadItem(query, handler); return; } CompletionStage<Runnable> last = tryLoad(manager, sockets.next().getRemoteUri(), query, handler); while (sockets.hasNext()) { URI uri = sockets.next().getRemoteUri(); //TODO: java 12 replace this with the line commented below var cf = new CompletableFuture<Runnable>(); last.thenApply(CompletableFuture::completedStage) .exceptionally(e -> tryLoad(manager, uri, query, handler)) .thenCompose(Function.identity()) .thenAccept(cf::complete) .exceptionally(e -> { cf.completeExceptionally(e); return null; }); last = cf; //last = last.exceptionallyCompose(e -> tryLoad(manager, uri, query, handler)); } last.whenComplete((ok, oof) -> { if (oof != null) { handler.loadFailed(new FriendlyException("Failed to load", FriendlyException.Severity.SUSPICIOUS, oof)); } else { ok.run(); } }); }
Example #8
Source File: YoutubeIpRotatorSetup.java From lavaplayer with Apache License 2.0 | 5 votes |
public YoutubeIpRotatorSetup forManager(AudioPlayerManager playerManager) { YoutubeAudioSourceManager sourceManager = playerManager.source(YoutubeAudioSourceManager.class); if (sourceManager != null) { forSource(sourceManager); } return this; }
Example #9
Source File: GuildMusicManager.java From lavaplayer with Apache License 2.0 | 5 votes |
/** * Creates a player and a track scheduler. * @param manager Audio player manager to use for creating the player. */ public GuildMusicManager(AudioPlayerManager manager) { player = manager.createPlayer(); scheduler = new TrackScheduler(player); player.addListener(scheduler); provider = new D4jAudioProvider(player); }
Example #10
Source File: PlayerManagerTestTools.java From lavaplayer with Apache License 2.0 | 5 votes |
public static AudioTrack loadTrack(AudioPlayerManager manager, String identifier) throws Exception { CompletableFuture<AudioTrack> result = new CompletableFuture<>(); manager.loadItem(identifier, new FunctionalResultHandler( result::complete, (playlist) -> result.completeExceptionally(new IllegalArgumentException()), () -> result.completeExceptionally(new NoSuchElementException()), result::completeExceptionally )); return result.get(10, TimeUnit.SECONDS); }
Example #11
Source File: AudioSourceManagers.java From lavaplayer with Apache License 2.0 | 5 votes |
/** * Registers all built-in remote audio sources to the specified player manager. Local file audio source must be * registered separately. * * @param playerManager Player manager to register the source managers to * @param containerRegistry Media container registry to be used by any probing sources. */ public static void registerRemoteSources(AudioPlayerManager playerManager, MediaContainerRegistry containerRegistry) { playerManager.registerSourceManager(new YoutubeAudioSourceManager(true)); playerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault()); playerManager.registerSourceManager(new BandcampAudioSourceManager()); playerManager.registerSourceManager(new VimeoAudioSourceManager()); playerManager.registerSourceManager(new TwitchStreamAudioSourceManager()); playerManager.registerSourceManager(new BeamAudioSourceManager()); playerManager.registerSourceManager(new GetyarnAudioSourceManager()); playerManager.registerSourceManager(new HttpAudioSourceManager(containerRegistry)); }
Example #12
Source File: Player.java From Lavalink with MIT License | 5 votes |
public Player(SocketContext socketContext, String guildId, AudioPlayerManager audioPlayerManager) { this.socketContext = socketContext; this.guildId = guildId; this.player = audioPlayerManager.createPlayer(); this.player.addListener(this); this.player.addListener(new EventEmitter(audioPlayerManager, this)); this.player.addListener(audioLossCounter); }
Example #13
Source File: Andesite.java From andesite-node with MIT License | 5 votes |
private static void configureYt(@Nonnull AudioPlayerManager manager, @Nonnull Config config) { var yt = manager.source(YoutubeAudioSourceManager.class); if(yt == null) { return; } yt.setPlaylistPageCount(config.getInt("lavaplayer.youtube.max-playlist-page-count")); yt.setMixLoaderMaximumPoolSize(config.getInt("lavaplayer.youtube.mix-loader-max-pool-size")); }
Example #14
Source File: RequestUtils.java From andesite-node with MIT License | 5 votes |
/** * Encodes the provided track to base64. * * @param playerManager Player manager used for encoding (must have the source manager enabled). * @param track Track to encode. * * @return Base64 encoded track. */ @Nonnull @CheckReturnValue public static String trackString(@Nonnull AudioPlayerManager playerManager, @Nonnull AudioTrack track) { var baos = new ByteArrayOutputStream(); try { playerManager.encodeTrack(new MessageOutput(baos), track); } catch(IOException e) { throw new AssertionError(e); } return Base64.getEncoder().encodeToString(baos.toByteArray()); }
Example #15
Source File: BaseAudioTrack.java From lavaplayer with Apache License 2.0 | 4 votes |
@Override public AudioTrackExecutor createLocalExecutor(AudioPlayerManager playerManager) { return null; }
Example #16
Source File: GuildMusicManager.java From lavaplayer with Apache License 2.0 | 4 votes |
/** * Creates a player and a track scheduler. * @param manager Audio player manager to use for creating the player. */ public GuildMusicManager(AudioPlayerManager manager) { player = manager.createPlayer(); scheduler = new TrackScheduler(player); player.addListener(scheduler); }
Example #17
Source File: BotApplicationManager.java From lavaplayer with Apache License 2.0 | 4 votes |
public AudioPlayerManager getPlayerManager() { return playerManager; }
Example #18
Source File: PluginManager.java From andesite-node with MIT License | 4 votes |
public void configurePlayerManager(@Nonnull AudioPlayerManager manager) { for(var p : plugins) { log.debug("Configuring player manager {} with plugin {}", manager, p); p.configurePlayerManager(state, manager); } }
Example #19
Source File: Andesite.java From andesite-node with MIT License | 4 votes |
@Nonnull @CheckReturnValue @Override public AudioPlayerManager audioPlayerManager() { return playerManager; }
Example #20
Source File: Andesite.java From andesite-node with MIT License | 4 votes |
@Nonnull @CheckReturnValue @Override public AudioPlayerManager pcmAudioPlayerManager() { return pcmPlayerManager; }
Example #21
Source File: MantaroAudioManager.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
public AudioPlayerManager getPlayerManager() { return this.playerManager; }
Example #22
Source File: TrackMixer.java From andesite-node with MIT License | 4 votes |
public TrackMixer(AudioPlayerManager playerManager, AndesitePlayer parent) { this.playerManager = playerManager; this.encoder = new OpusChunkEncoder(playerManager.getConfiguration(), StandardAudioDataFormats.DISCORD_OPUS); this.parent = parent; }
Example #23
Source File: AudioSourceManagers.java From lavaplayer with Apache License 2.0 | 4 votes |
/** * See {@link #registerRemoteSources(AudioPlayerManager, MediaContainerRegistry)}, but with default containers. */ public static void registerRemoteSources(AudioPlayerManager playerManager) { registerRemoteSources(playerManager, MediaContainerRegistry.DEFAULT_REGISTRY); }
Example #24
Source File: Discord.java From DiscordBot with Apache License 2.0 | 4 votes |
public AudioPlayerManager getAudioPlayerManager() { return audioPlayerManager; }
Example #25
Source File: VoiceSupport.java From Discord4J with GNU Lesser General Public License v3.0 | 4 votes |
public static Mono<Void> voiceHandler(GatewayDiscordClient client) { AudioPlayerManager playerManager = new DefaultAudioPlayerManager(); playerManager.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new); AudioSourceManagers.registerRemoteSources(playerManager); AudioPlayer player = playerManager.createPlayer(); AudioProvider provider = new LavaplayerAudioProvider(player); Mono<Void> join = client.getEventDispatcher().on(MessageCreateEvent.class) .filter(e -> e.getMessage().getContent().equals("!join")) .doOnNext(e -> log.info("Received voice join request")) .flatMap(e -> Mono.justOrEmpty(e.getMember()) .flatMap(Member::getVoiceState) .flatMap(VoiceState::getChannel) .flatMap(channel -> channel.join(spec -> spec.setProvider(provider))) .doFinally(s -> log.info("Finalized join request after {}", s)) .onErrorResume(t -> { log.error("Failed to join voice channel", t); return Mono.empty(); })) .then(); Mono<Void> leave = client.getEventDispatcher().on(MessageCreateEvent.class) .filter(e -> e.getMessage().getContent().equals("!leave")) .doOnNext(e -> log.info("Received voice leave request")) .flatMap(e -> Mono.justOrEmpty(e.getMember()) .flatMap(Member::getVoiceState) .flatMap(vs -> client.getVoiceConnectionRegistry() .getVoiceConnection(vs.getGuildId()) .doOnSuccess(vc -> { if (vc == null) { log.info("No voice connection to leave!"); } })) .flatMap(VoiceConnection::disconnect)) .then(); Mono<Void> reconnect = client.getEventDispatcher().on(MessageCreateEvent.class) .filter(e -> e.getMessage().getContent().equals("!vcretry")) .flatMap(e -> Mono.justOrEmpty(e.getMember()) .flatMap(Member::getVoiceState) .flatMap(vs -> client.getVoiceConnectionRegistry() .getVoiceConnection(vs.getGuildId())) .flatMap(VoiceConnection::reconnect) .doFinally(s -> log.info("Reconnect event handle complete"))) .then(); Mono<Void> play = client.getEventDispatcher().on(MessageCreateEvent.class) .filter(e -> e.getMessage().getContent().startsWith("!play ")) .flatMap(e -> Mono.justOrEmpty(e.getMessage().getContent()) .map(content -> Arrays.asList(content.split(" "))) .doOnNext(command -> playerManager.loadItem(command.get(1), new MyAudioLoadResultHandler(player)))) .then(); Mono<Void> stop = client.getEventDispatcher().on(MessageCreateEvent.class) .filter(e -> e.getMessage().getContent().equals("!stop")) .doOnNext(e -> player.stopTrack()) .then(); Mono<Void> currentGuild = client.getEventDispatcher().on(MessageCreateEvent.class) .filter(e -> e.getMessage().getContent().equals("!vcguild")) .flatMap(e -> Mono.justOrEmpty(e.getMember()) .flatMap(Member::getVoiceState) .flatMap(vs -> e.getMessage().getRestChannel().createMessage( MessageCreateRequest.builder() .content(vs.getGuildId().asString()) .build()))) .then(); return Mono.zip(join, leave, reconnect, play, stop, currentGuild, client.onDisconnect()).then(); }
Example #26
Source File: Util.java From Lavalink with MIT License | 4 votes |
public static String toMessage(AudioPlayerManager audioPlayerManager, AudioTrack track) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); audioPlayerManager.encodeTrack(new MessageOutput(baos), track); return Base64.encodeBase64String(baos.toByteArray()); }
Example #27
Source File: Util.java From Lavalink with MIT License | 4 votes |
public static AudioTrack toAudioTrack(AudioPlayerManager audioPlayerManager, String message) throws IOException { byte[] b64 = Base64.decodeBase64(message); ByteArrayInputStream bais = new ByteArrayInputStream(b64); return audioPlayerManager.decodeTrack(new MessageInput(bais)).decodedTrack; }
Example #28
Source File: Player.java From andesite-node with MIT License | 4 votes |
@Nonnull @CheckReturnValue public AudioPlayerManager audioPlayerManager() { return audioPlayerManager; }
Example #29
Source File: AudioLoader.java From Lavalink with MIT License | 4 votes |
public AudioLoader(AudioPlayerManager audioPlayerManager) { this.audioPlayerManager = audioPlayerManager; }
Example #30
Source File: AudioLoaderRestHandler.java From Lavalink with MIT License | 4 votes |
public AudioLoaderRestHandler(AudioPlayerManager audioPlayerManager, ServerConfig serverConfig) { this.audioPlayerManager = audioPlayerManager; this.serverConfig = serverConfig; }