com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers Java Examples

The following examples show how to use com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers. 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: MusicManager.java    From Shadbot with GNU General Public License v3.0 6 votes vote down vote up
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 #2
Source File: LocalPlayerDemo.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: Discord.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public void loadDiscord() {
	try {
		jda = new JDABuilder(AccountType.BOT)
				.setToken(DiscordBot.getInstance().getConfig().getToken())
				.addEventListener(new DiscordListener())
				.setAudioEnabled(true)
				.setBulkDeleteSplittingEnabled(false)
				.buildAsync();
		
		AudioSourceManagers.registerRemoteSources(getAudioPlayerManager());
		audioPlayer = getAudioPlayerManager().createPlayer();
		getAudioPlayer().setVolume(DiscordBot.getInstance().getConfig().getDefaultVolume());
		getAudioPlayer().addListener(new AudioListener());
		getDiscordThread().start();
		getCommand().registerCommands();
		LogHelper.info("Successfully loaded Discord.");
	} catch (LoginException | RateLimitedException | RuntimeException ex) {
		LogHelper.error("Exception loading Discord!");
		ex.printStackTrace();
	}
}
 
Example #4
Source File: Main.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private Main() {
  this.musicManagers = new ConcurrentHashMap<>();

  this.playerManager = new DefaultAudioPlayerManager();
  AudioSourceManagers.registerRemoteSources(playerManager);
  AudioSourceManagers.registerLocalSource(playerManager);
}
 
Example #5
Source File: PlayingTrackManager.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Autowired
public PlayingTrackManager(StatisticsManager statisticsManager) {
  this.statisticsManager = statisticsManager;
  manager = new DefaultAudioPlayerManager();
  tracks = new ConcurrentHashMap<>();

  manager.setUseSeekGhosting(false);
  AudioSourceManagers.registerRemoteSources(manager);
}
 
Example #6
Source File: Main.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private Main() {
  this.musicManagers = new HashMap<>();

  this.playerManager = new DefaultAudioPlayerManager();
  AudioSourceManagers.registerRemoteSources(playerManager);
  AudioSourceManagers.registerLocalSource(playerManager);
}
 
Example #7
Source File: Music.java    From DiscordBot with Apache License 2.0 4 votes vote down vote up
public Music() {
    AudioSourceManagers.registerRemoteSources(myManager);
}
 
Example #8
Source File: VoiceSupport.java    From Discord4J with GNU Lesser General Public License v3.0 4 votes vote down vote up
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();
}