com.sedmelluq.discord.lavaplayer.track.playback.NonAllocatingAudioFrameBuffer Java Examples
The following examples show how to use
com.sedmelluq.discord.lavaplayer.track.playback.NonAllocatingAudioFrameBuffer.
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: LocalMusicManager.java From kyoko with MIT License | 7 votes |
public LocalMusicManager(Vertx vertx, MusicSettings settings, EventManager eventManager) { this.vertx = vertx; this.eventManager = eventManager; this.sourceManagers = new ArrayList<>(); this.players = new HashMap<>(); this.queues = new HashMap<>(); this.pendingLeave = new HashMap<>(); this.audioConnections = new HashMap<>(); this.queueLimit = settings.queueLimit; playerManager = new DefaultAudioPlayerManager(); playerManager.setFrameBufferDuration(300); playerManager.getConfiguration().setFilterHotSwapEnabled(true); playerManager.getConfiguration().setOpusEncodingQuality(10); playerManager.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new); eventManager.registerEventHandler(DiscordEvent.CHANNEL_DELETE, this::onChannelDelete); eventManager.registerEventHandler(DiscordEvent.GUILD_DELETE, this::onLeave); eventManager.registerEventHandler(DiscordEvent.VOICE_STATE_UPDATE, this::onVoiceStateUpdate); LocalPlayerWrapper.configuration = playerManager.getConfiguration(); LocalPlayerWrapper.settings = settings; }
Example #2
Source File: MusicManager.java From Shadbot with GNU General Public License v3.0 | 6 votes |
private MusicManager() { this.audioPlayerManager = new DefaultAudioPlayerManager(); this.audioPlayerManager.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new); this.audioPlayerManager.getConfiguration().setFilterHotSwapEnabled(true); AudioSourceManagers.registerRemoteSources(this.audioPlayerManager); this.guildMusics = new ConcurrentHashMap<>(); this.guildJoining = new ConcurrentHashMap<>(); //IPv6 rotation config final String ipv6Block = CredentialManager.getInstance().get(Credential.IPV6_BLOCK); if (!Config.IS_SNAPSHOT && ipv6Block != null && !ipv6Block.isBlank()) { LOGGER.info("Configuring YouTube IP rotator"); final List<IpBlock> blocks = Collections.singletonList(new Ipv6Block(ipv6Block)); final AbstractRoutePlanner planner = new RotatingNanoIpRoutePlanner(blocks); new YoutubeIpRotatorSetup(planner) .forSource(this.audioPlayerManager.source(YoutubeAudioSourceManager.class)) .setup(); } }
Example #3
Source File: MantaroAudioManager.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("rawtypes") public MantaroAudioManager() { this.musicManagers = new ConcurrentHashMap<>(); this.playerManager = new DefaultAudioPlayerManager(); //Youtube is special because rotation stuff. YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager(true); //IPv6 rotation config start Config config = MantaroData.config().get(); if (!config.getIpv6Block().isEmpty()) { AbstractRoutePlanner planner; String block = config.getIpv6Block(); List<IpBlock> blocks = Collections.singletonList(new Ipv6Block(block)); //Damn you, YouTube. if (config.getExcludeAddress().isEmpty()) planner = new RotatingNanoIpRoutePlanner(blocks); else { try { InetAddress blacklistedGW = InetAddress.getByName(config.getExcludeAddress()); planner = new RotatingNanoIpRoutePlanner(blocks, inetAddress -> !inetAddress.equals(blacklistedGW)); } catch (Exception e) { //Fallback: did I screw up putting the IP in? lmao planner = new RotatingNanoIpRoutePlanner(blocks); e.printStackTrace(); } } new YoutubeIpRotatorSetup(planner) .forSource(youtubeAudioSourceManager) .setup(); } //IPv6 rotation config end //Register source manager and configure the Player playerManager.registerSourceManager(youtubeAudioSourceManager); playerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault()); playerManager.registerSourceManager(new BandcampAudioSourceManager()); playerManager.registerSourceManager(new VimeoAudioSourceManager()); playerManager.registerSourceManager(new TwitchStreamAudioSourceManager()); playerManager.registerSourceManager(new BeamAudioSourceManager()); if (!ExtraRuntimeOptions.DISABLE_NON_ALLOCATING_BUFFER) { log.info("Enabled non-allocating audio buffer."); playerManager.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new); } }
Example #4
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(); }