Java Code Examples for com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager#createPlayer()
The following examples show how to use
com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager#createPlayer() .
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: 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 2
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 3
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 4
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 5
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 6
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(); }