本文整理汇总了Java中com.sedmelluq.discord.lavaplayer.player.AudioPlayer类的典型用法代码示例。如果您正苦于以下问题:Java AudioPlayer类的具体用法?Java AudioPlayer怎么用?Java AudioPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AudioPlayer类属于com.sedmelluq.discord.lavaplayer.player包,在下文中一共展示了AudioPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTrackStart
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public final void onTrackStart(AudioPlayer player, AudioTrack track) {
SupremeBot.setStatus(track.getInfo().title);
System.out.println("voiceChannel: " + voiceChannel);
if (voiceChannel == null) { //FIXME Wtf why would this happen??!
try {
if (player.getPlayingTrack() != null) {
player.stopTrack();
}
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
setVoiceChannel(voiceChannel);
}
}
示例2: onTrackEnd
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
// loop
boolean loop = AudioPlayerThread.loop && (endReason == AudioTrackEndReason.FINISHED);
// save old track
AudioTrack loopTrack = null;
if(loop) {
loopTrack = track.makeClone();
}
// Only start the next track if the end reason is suitable for it
// (FINISHED or LOAD_FAILED)
if (endReason.mayStartNext) {
nextTrack();
}
// re add track if loop is enabled
if (loop) {
queue(loopTrack);
}
}
示例3: onTrackStart
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
player.setPaused(false);
if (permissions.canPost(channel)) {
if (current != null && current.getIdentifier().equals(track.getIdentifier()))
return;
current = track;
channel.sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("Now Playing")
.setDescription(track.getInfo().title)
.build()
).queue();
}
}
示例4: onTrackException
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException err) {
errorCount++;
String errMessage = Jsoup.parse(StringUtils.remove(err.getMessage(), "Watch on YouTube")).text().trim();
if(errorCount <= 3) {
BotUtils.sendMessage(String.format(Emoji.RED_CROSS + " Sorry, %s. I'll try to play the next available song.",
errMessage.toLowerCase()), guildMusic.getChannel());
}
if(errorCount == 3) {
BotUtils.sendMessage(Emoji.RED_FLAG + " Too many errors in a row, I will ignore them until finding a music that can be played.",
guildMusic.getChannel());
LogUtils.infof("{Guild ID: %d} Too many errors in a row. They will be ignored until music can be played.",
guildMusic.getChannel().getGuild().getLongID());
}
LogUtils.infof("{Guild ID: %d} %sTrack exception: %s",
guildMusic.getChannel().getGuild().getLongID(), errorCount > 3 ? "(Ignored) " : "", errMessage);
if(!guildMusic.getScheduler().nextTrack()) {
guildMusic.end();
}
}
示例5: execute
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void execute(Context context) throws MissingArgumentException {
GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
if(guildMusic == null || guildMusic.getScheduler().isStopped()) {
BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
return;
}
AudioPlayer audioPlayer = guildMusic.getScheduler().getAudioPlayer();
audioPlayer.setPaused(!audioPlayer.isPaused());
if(audioPlayer.isPaused()) {
BotUtils.sendMessage(String.format(Emoji.PAUSE + " Music paused by **%s**.", context.getAuthorName()), context.getChannel());
} else {
BotUtils.sendMessage(String.format(Emoji.PLAY + " Music resumed by **%s**.", context.getAuthorName()), context.getChannel());
}
}
示例6: onTrackEnd
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
if (endReason.mayStartNext) {
if (manager.isRepeatQueue()) {
queue.offer(new AudioTrackContainer(track.makeClone(), getAudioTrackContainer().getRequester()));
}
nextTrack();
return;
}
if (endReason.equals(AudioTrackEndReason.FINISHED) && queue.isEmpty()) {
if (manager.getLastActiveMessage() != null) {
service.submit(this::handleEndOfQueueWithLastActiveMessage);
}
}
}
示例7: onTrackStart
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
TextChannel ch;
if (GuildObject.guildMap.get(this.guildId).getSpecialChannels().getMusic().isEmpty()) {
return;
}
if((ch = Bot.getInstance().shards
.getTextChannelById(GuildObject.guildMap.get(this.guildId)
.getSpecialChannels().getMusic())) != null) {
if (!track.getInfo().isStream) {
EmbedBuilder em = new EmbedBuilder();
em.setTitle("New track: " + track.getInfo().title, track.getInfo().uri)
.setColor(Color.MAGENTA)
.setDescription(String.format("%s, **%s** is now playing\n"
+ "%s", this.currentSong.getQueuer().getAsMention(),
track.getInfo().title, track.getInfo().uri));
ch.sendMessage(em.build()).queue();
}
}
}
示例8: onTrackEnd
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
JSONObject out = new JSONObject();
out.put("op", "event");
out.put("type", "TrackEndEvent");
out.put("guildId", linkPlayer.getGuildId());
try {
out.put("track", Util.toMessage(track));
} catch (IOException e) {
out.put("track", JSONObject.NULL);
}
out.put("reason", endReason.toString());
linkPlayer.getSocket().getSocket().send(out.toString());
}
示例9: onTrackException
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) {
JSONObject out = new JSONObject();
out.put("op", "event");
out.put("type", "TrackExceptionEvent");
out.put("guildId", linkPlayer.getGuildId());
try {
out.put("track", Util.toMessage(track));
} catch (IOException e) {
out.put("track", JSONObject.NULL);
}
out.put("error", exception.getMessage());
linkPlayer.getSocket().getSocket().send(out.toString());
}
示例10: onTrackStuck
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackStuck(AudioPlayer player, AudioTrack track, long thresholdMs) {
log.warn(track.getInfo().title + " got stuck! Threshold surpassed: " + thresholdMs);
JSONObject out = new JSONObject();
out.put("op", "event");
out.put("type", "TrackStuckEvent");
out.put("guildId", linkPlayer.getGuildId());
try {
out.put("track", Util.toMessage(track));
} catch (IOException e) {
out.put("track", JSONObject.NULL);
}
out.put("thresholdMs", thresholdMs);
linkPlayer.getSocket().getSocket().send(out.toString());
SocketServer.sendPlayerUpdate(linkPlayer.getSocket().getSocket(), linkPlayer);
}
示例11: onTrackEnd
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackEnd(AudioPlayer audioPlayer, AudioTrack audioTrack, AudioTrackEndReason audioTrackEndReason) {
if (audioTrackEndReason.equals(AudioTrackEndReason.FINISHED) && audioTrackEndReason.mayStartNext) {
LogHelper.debug("Track Finished, Playing next.");
DiscordBot.getInstance().getDiscord().getAudioQueue().playNext();
return;
}
if (audioTrackEndReason.equals(AudioTrackEndReason.STOPPED)) {
LogHelper.debug("Track stopped.");
return;
}
if (audioTrackEndReason.equals(AudioTrackEndReason.REPLACED)) {
LogHelper.debug("Track replaced.");
}
}
示例12: setUpHandler
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
public AudioHandler setUpHandler(Guild guild)
{
AudioHandler handler;
if(guild.getAudioManager().getSendingHandler()==null)
{
AudioPlayer player = manager.createPlayer();
if(settings.containsKey(guild.getId()))
player.setVolume(settings.get(guild.getId()).getVolume());
handler = new AudioHandler(player, guild, this);
player.addListener(handler);
guild.getAudioManager().setSendingHandler(handler);
if(AudioHandler.USE_NP_REFRESH)
threadpool.scheduleWithFixedDelay(() -> updateLastNP(guild.getIdLong()), 0, 5, TimeUnit.SECONDS);
}
else
handler = (AudioHandler)guild.getAudioManager().getSendingHandler();
return handler;
}
示例13: onTrackEnd
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
if(endReason==AudioTrackEndReason.FINISHED && bot.getSettings(bot.getJDA().getGuildById(guildId)).getRepeatMode())
{
queue.add(new QueuedTrack(track.makeClone(), requester));
}
requester = 0;
if(queue.isEmpty())
{
if(!playFromDefault())
{
if(SONG_IN_STATUS)
bot.resetGame();
if(!STAY_IN_CHANNEL)
bot.getThreadpool().submit(() -> bot.getJDA().getGuildById(guildId).getAudioManager().closeAudioConnection());
bot.updateTopic(guildId, this);
}
}
else
{
QueuedTrack qt = queue.pull();
requester = qt.getIdentifier();
player.playTrack(qt.getTrack());
}
}
示例14: main
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
public static void main(String[] args) throws LineUnavailableException, IOException {
AudioPlayerManager manager = new DefaultAudioPlayerManager();
AudioSourceManagers.registerRemoteSources(manager);
manager.getConfiguration().setOutputFormat(new AudioDataFormat(2, 44100, 960, AudioDataFormat.Codec.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[format.bufferSize(2)];
int chunkSize;
while ((chunkSize = stream.read(buffer)) >= 0) {
line.write(buffer, 0, chunkSize);
}
}
示例15: onTrackStart
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; //导入依赖的package包/类
@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
IChannel ch;
if((ch = Bot.getInstance().getBot()
.getChannelByID(Guild.guildMap.get(this.guildId)
.getSpecialChannels().getMusic())) != null) {
EmbedBuilder em = new EmbedBuilder();
em.withTitle("New track: " + this.getCurrentSong().getTitle() == null ?
track.getInfo().title :
this.getCurrentSong().getTitle())
.withColor(Color.MAGENTA);
if(currentSong != null)
em.withDesc(String.format("<@%s>, **%s** is now playing\n"
+ "%s", this.currentSong.getQueuer().getID(),
this.getCurrentSong().getTitle() == null ? track.getInfo().title : this.getCurrentSong().getTitle(),
this.currentSong.getUrl()));
MessageUtils.sendMessage(ch, em.build());
}
}