本文整理汇总了Java中com.sedmelluq.discord.lavaplayer.track.AudioTrack类的典型用法代码示例。如果您正苦于以下问题:Java AudioTrack类的具体用法?Java AudioTrack怎么用?Java AudioTrack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AudioTrack类属于com.sedmelluq.discord.lavaplayer.track包,在下文中一共展示了AudioTrack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postDecodeTracks
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
@PostMapping(value = "/decodetracks", consumes = "application/json", produces = "application/json")
@ResponseBody
public String postDecodeTracks(HttpServletRequest request, HttpServletResponse response, @RequestBody String body) throws IOException {
log(request);
if (!isAuthorized(request, response))
return "";
JSONArray requestJSON = new JSONArray(body);
JSONArray responseJSON = new JSONArray();
for (int i = 0; i < requestJSON.length(); i++) {
String track = requestJSON.getString(i);
AudioTrack audioTrack = Util.toAudioTrack(track);
JSONObject infoJSON = trackToJSON(audioTrack);
JSONObject trackJSON = new JSONObject()
.put("track", track)
.put("info", infoJSON);
responseJSON.put(trackJSON);
}
return responseJSON.toString();
}
示例2: compareTracks
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
private boolean compareTracks(AudioTrack track1, AudioTrack track2) {
if (Objects.equals(track1, track2)) {
return true;
}
AudioTrackInfo info1 = track1.getInfo();
AudioTrackInfo info2 = track2.getInfo();
if (info1 != null && info2 != null) {
return Objects.equals(info1.uri, info2.uri)
&& Objects.equals(info1.uri, info2.uri)
&& Objects.equals(info1.title, info2.title)
&& Objects.equals(info1.author, info2.author)
&& Objects.equals(info1.identifier, info2.identifier)
&& Objects.equals(info1.length, info2.length)
&& Objects.equals(info1.isStream, info2.isStream);
}
return Objects.equals(info1, info1);
}
示例3: onTrackStart
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的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);
}
}
示例4: playTrack
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
@Override
public void playTrack(AudioTrack track) {
try {
position = track.getPosition();
TrackData trackData = track.getUserData(TrackData.class);
JSONObject json = new JSONObject();
json.put("op", "play");
json.put("guildId", link.getGuildId());
json.put("track", LavalinkUtil.toMessage(track));
json.put("startTime", position);
if (trackData != null) {
json.put("startTime", trackData.startPos);
json.put("endTime", trackData.endPos);
}
json.put("pause", paused);
link.getNode(true).send(json.toString());
updateTime = System.currentTimeMillis();
this.track = track;
emitEvent(new TrackStartEvent(this, track));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: onTrackEnd
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的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);
}
}
}
示例6: resort
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
/**
* Resorts the playlist
*/
public void resort() {
synchronized (this) {
// Insertion sort the playlist according to https://en.wikipedia.org/wiki/Insertion_sort
AudioTrack[] tracks = sortedPlaylist.toArray(new AudioTrack[sortedPlaylist.size()]);
for (int i = 1; i < tracks.length; i++) {
AudioTrack x = tracks[i];
int j = i - 1;
while (j >= 0 && compareByVotesAndID.compare(tracks[j], x) > 0) {
tracks[j + 1] = tracks[j];
j--;
}
tracks[j + 1] = x;
}
sortedPlaylist = new ArrayList<>(Arrays.asList(tracks));
RequestSender.broadcastPlaylist();
}
}
示例7: queueTrack
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
public boolean queueTrack(AudioTrack track, CommandEvent event, Message m) {
if (event.getMember().getVoiceState().getChannel() == null) {
m.editMessage(event.getClient().getWarning() + " You are not in a voice channel! Please join one to use this command.").queue();
return false;
}
else if (!event.getSelfMember().hasPermission(event.getMember().getVoiceState().getChannel(), Permission.VOICE_CONNECT)) {
m.editMessage(event.getClient().getWarning() + " I don't have permission to join your voice channel. :cry:").queue();
return false;
}
else if (!event.getSelfMember().hasPermission(event.getMember().getVoiceState().getChannel(), Permission.VOICE_SPEAK)){
m.editMessage(event.getClient().getWarning() + " I don't have permission to speak in your voice channel. :cry:").queue();
return false;
}
else {
getHandler(event.getGuild()).queueTrack(track, event.getAuthor().getIdLong());
if (!event.getGuild().getAudioManager().isConnected()) {
event.getGuild().getAudioManager().openAudioConnection(event.getMember().getVoiceState().getChannel());
}
return true;
}
}
示例8: onTrackException
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的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());
}
示例9: trackLoaded
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
@Override
public void trackLoaded(AudioTrack track) {
if (!canQueueTrack(track, e.getAuthor().getIdLong())) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("Track Unavailable")
.setDescription("This track exceeds certain limits. [Remove these limits by donating!](https://patreon.com/Devoxin)")
.build()
).queue();
return;
}
if (musicManager.addToQueue(track, e.getAuthor().getIdLong()))
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("Track Enqueued")
.setDescription(track.getInfo().title)
.build()
).queue();
}
示例10: canQueueTrack
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
private boolean canQueueTrack(AudioTrack track, long requesterID) {
final int trackLength = (int) Math.ceil(track.getDuration() / 1000);
final int requesterTier = permissions.getTierLevel(requesterID);
/* 7500 = ~ 2 hours
* 18500 = ~ 5 hours
*/
int maxTrackDuration = 7500;
if (requesterTier == 1)
maxTrackDuration = 18500;
if (requesterTier >= 2)
maxTrackDuration = Integer.MAX_VALUE;
return !JukeBot.limitationsEnabled || (track.getInfo().isStream && requesterTier != 0) || trackLength <= maxTrackDuration;
}
示例11: poll
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
/**
* Returns the next track in order.
*
* @return the next track in order, or null if the playlist is empty
*/
public AudioTrack poll() {
synchronized (this) {
if (sortedPlaylist.isEmpty()) {
// Broadcast to users
JsonObject data = new JsonObject();
data.addProperty("state", "stopped");
data.add("track", null);
WsPackage.create().resource(Server.Resource.PLAYER).action(Server.Action.DATA).data(data).broadcast();
return null;
}
AudioTrack track = sortedPlaylist.remove(0);
trackSet.remove(((AudioTrackMetaData) track.getUserData()).getTrackID());
RequestSender.broadcastPlaylist();
return track;
}
}
示例12: onTrackStuck
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的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);
}
示例13: onTrackStart
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
deletePlayingMessage();
guildMusicPlayer.textChannel.sendMessage("Now playing " + track.getInfo().title).queue(m->
playingMessageId = m.getIdLong()
);
}
示例14: onTrackEnd
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
@Override
public final void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
if (endReason != AudioTrackEndReason.REPLACED) {
if (loopType.isLoop() && loopType.isSingle()) {
player.playTrack(track.makeClone());
} else {
playNext();
}
}
}
示例15: onTrackEnd
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; //导入依赖的package包/类
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
// Only start the next track if the end reason is suitable for it (FINISHED or LOAD_FAILED)
if (endReason.mayStartNext) {
nextTrack();
}
}