Skip to content

Commit

Permalink
rename Track -> AudioTrack, TrackInfo -> AudioTrackInfo & TrackEndRea…
Browse files Browse the repository at this point in the history
…son -> AudioTrackEndReason
  • Loading branch information
topi314 committed Jan 7, 2022
1 parent 6477a82 commit db7a0e0
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 103 deletions.
32 changes: 16 additions & 16 deletions src/main/java/lavalink/client/io/LavalinkRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void setHttpClientBuilder(final Consumer<HttpClientBuilder> clientBuilder
* @return a list of YouTube search results as {@code AudioTrack audio tracks}
*/
@NonNull
public CompletableFuture<List<Track>> getYoutubeSearchResult(final String query) {
public CompletableFuture<List<AudioTrack>> getYoutubeSearchResult(final String query) {
return load(YOUTUBE_SEARCH_PREFIX + query)
.thenApplyAsync(LavalinkRestClient::transformSearchResult);
}
Expand All @@ -90,7 +90,7 @@ public CompletableFuture<List<Track>> getYoutubeSearchResult(final String query)
* @return a list of SoundCloud search results as {@code AudioTrack audio tracks}
*/
@NonNull
public CompletableFuture<List<Track>> getSoundcloudSearchResult(final String query) {
public CompletableFuture<List<AudioTrack>> getSoundcloudSearchResult(final String query) {
return load(SOUNDCLOUD_SEARCH_PREFIX + query)
.thenApplyAsync(LavalinkRestClient::transformSearchResult);
}
Expand Down Expand Up @@ -155,9 +155,9 @@ private CompletableFuture<JSONObject> load(final String identifier) {
});
}

private static List<Track> transformSearchResult(JSONObject loadResult) {
private static List<AudioTrack> transformSearchResult(JSONObject loadResult) {
return loadResult.getJSONArray("tracks").toList().stream().map(track ->
new DefaultTrack(new JSONObject((Map<?, ?>) track).getString("track"))
new DefaultAudioTrack(new JSONObject((Map<?, ?>) track).getString("track"))
).collect(Collectors.toList());
}

Expand Down Expand Up @@ -199,23 +199,23 @@ private TrackLoadResultHandler(JSONObject loadResult) {
this.loadResult = loadResult;
}

private Track handleTrackLoaded() {
private AudioTrack handleTrackLoaded() {
JSONObject trackObject = loadResult.getJSONArray("tracks").getJSONObject(0);
String singleTrackBase64 = trackObject.getString("track");
TrackInfo trackInfo = DefaultTrackInfo.fromJSON(trackObject.getJSONObject("info"));
AudioTrackInfo trackInfo = DefaultAudioTrackInfo.fromJSON(trackObject.getJSONObject("info"));

return new DefaultTrack(singleTrackBase64, trackInfo);
return new DefaultAudioTrack(singleTrackBase64, trackInfo);
}

private Playlist handlePlaylistLoaded() {
private AudioPlaylist handlePlaylistLoaded() {
JSONArray trackData = loadResult.getJSONArray("tracks");
final List<Track> tracks = new ArrayList<>();
final List<AudioTrack> tracks = new ArrayList<>();

for (Object track : trackData) {
String trackBase64 = ((JSONObject) track).getString("track");
TrackInfo trackInfo = DefaultTrackInfo.fromJSON(((JSONObject) track).getJSONObject("info"));
AudioTrackInfo trackInfo = DefaultAudioTrackInfo.fromJSON(((JSONObject) track).getJSONObject("info"));

tracks.add(new DefaultTrack(trackBase64, trackInfo));
tracks.add(new DefaultAudioTrack(trackBase64, trackInfo));
}

if (tracks.size() == 0) {
Expand All @@ -224,18 +224,18 @@ private Playlist handlePlaylistLoaded() {

final JSONObject playlistInfo = loadResult.getJSONObject("playlistInfo");

return new DefaultPlaylist(playlistInfo.getString("name"), tracks, playlistInfo.optInt("selectedTrack", -1));
return new DefaultAudioPlaylist(playlistInfo.getString("name"), tracks, playlistInfo.optInt("selectedTrack", -1));
}

private List<Track> handleSearchResultLoaded() {
private List<AudioTrack> handleSearchResultLoaded() {
JSONArray trackData = loadResult.getJSONArray("tracks");
List<Track> tracks = new ArrayList<>();
List<AudioTrack> tracks = new ArrayList<>();

for (Object track : trackData) {
String trackBase64 = ((JSONObject) track).getString("track");
TrackInfo trackInfo = DefaultTrackInfo.fromJSON(((JSONObject) track).getJSONObject("info"));
AudioTrackInfo trackInfo = DefaultAudioTrackInfo.fromJSON(((JSONObject) track).getJSONObject("info"));

tracks.add(new DefaultTrack(trackBase64, trackInfo));
tracks.add(new DefaultAudioTrack(trackBase64, trackInfo));
}

if (tracks.size() == 0) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/lavalink/client/io/LavalinkSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import edu.umd.cs.findbugs.annotations.Nullable;
import lavalink.client.player.LavalinkPlayer;
import lavalink.client.player.event.*;
import lavalink.client.player.track.DefaultTrack;
import lavalink.client.player.track.TrackEndReason;
import lavalink.client.player.track.DefaultAudioTrack;
import lavalink.client.player.track.AudioTrackEndReason;
import org.java_websocket.drafts.Draft;
import org.java_websocket.handshake.ServerHandshake;
import org.json.JSONObject;
Expand Down Expand Up @@ -129,12 +129,12 @@ private void handleEvent(JSONObject json) throws IOException {

switch (json.getString("type")) {
case "TrackStartEvent":
event = new TrackStartEvent(player, new DefaultTrack(json.getString("track"), player.getPlayingTrack()));
event = new TrackStartEvent(player, new DefaultAudioTrack(json.getString("track"), player.getPlayingTrack()));
break;
case "TrackEndEvent":
TrackEndReason endReason = TrackEndReason.valueOf(json.getString("reason"));
event = new TrackEndEvent(player, new DefaultTrack(json.getString("track"), player.getPlayingTrack()), endReason);
if (endReason != TrackEndReason.REPLACED && endReason != TrackEndReason.STOPPED) {
AudioTrackEndReason endReason = AudioTrackEndReason.valueOf(json.getString("reason"));
event = new TrackEndEvent(player, new DefaultAudioTrack(json.getString("track"), player.getPlayingTrack()), endReason);
if (endReason != AudioTrackEndReason.REPLACED && endReason != AudioTrackEndReason.STOPPED) {
player.clearTrack();
}
break;
Expand All @@ -148,10 +148,10 @@ private void handleEvent(JSONObject json) throws IOException {
ex = new RemoteTrackException(json.getString("error"));
}

event = new TrackExceptionEvent(player, new DefaultTrack(json.getString("track"), player.getPlayingTrack()), ex);
event = new TrackExceptionEvent(player, new DefaultAudioTrack(json.getString("track"), player.getPlayingTrack()), ex);
break;
case "TrackStuckEvent":
event = new TrackStuckEvent(player, new DefaultTrack(json.getString("track"), player.getPlayingTrack()), json.getLong("thresholdMs"));
event = new TrackStuckEvent(player, new DefaultAudioTrack(json.getString("track"), player.getPlayingTrack()), json.getLong("thresholdMs"));
break;
case "WebSocketClosedEvent":
// Unlike the other events, this is handled by the Link instead of the LavalinkPlayer,
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/lavalink/client/io/LoadResultHandler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lavalink.client.io;

import lavalink.client.player.track.Playlist;
import lavalink.client.player.track.Track;
import lavalink.client.player.track.AudioPlaylist;
import lavalink.client.player.track.AudioTrack;

import java.util.List;

Expand All @@ -11,21 +11,21 @@ public interface LoadResultHandler {
*
* @param track The loaded track
*/
void trackLoaded(Track track);
void trackLoaded(AudioTrack track);

/**
* Called when the requested item is a playlist and it was successfully loaded.
*
* @param playlist The loaded playlist
*/
void playlistLoaded(Playlist playlist);
void playlistLoaded(AudioPlaylist playlist);

/**
* Called when the requested item is a search result and it was successfully loaded.
*
* @param tracks The loaded tracks from the search
*/
void searchResultLoaded(List<Track> tracks);
void searchResultLoaded(List<AudioTrack> tracks);

/**
* Called when there were no items found by the specified identifier.
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/lavalink/client/player/IPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
package lavalink.client.player;

import lavalink.client.player.event.IPlayerEventListener;
import lavalink.client.player.track.Track;
import lavalink.client.player.track.AudioTrack;

public interface IPlayer {

Track getPlayingTrack();
AudioTrack getPlayingTrack();

void playTrack(Track track);
void playTrack(AudioTrack track);

void playTrack(Track track, long startTime, long endTime);
void playTrack(AudioTrack track, long startTime, long endTime);

void stopTrack();

Expand All @@ -40,6 +40,7 @@ public interface IPlayer {

boolean isPaused();

@SuppressWarnings("unused")
long getTrackPosition();

@SuppressWarnings("unused")
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/lavalink/client/player/LavalinkPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import lavalink.client.player.event.PlayerEvent;
import lavalink.client.player.event.PlayerPauseEvent;
import lavalink.client.player.event.PlayerResumeEvent;
import lavalink.client.player.track.Track;
import lavalink.client.player.track.AudioTrack;
import org.json.JSONArray;
import org.json.JSONObject;

Expand All @@ -40,7 +40,7 @@

public class LavalinkPlayer implements IPlayer {

private Track track = null;
private AudioTrack track = null;
private boolean paused = false;
private int volume = 100;
private long updateTime = -1;
Expand Down Expand Up @@ -69,25 +69,25 @@ public LavalinkPlayer(Link link) {
* Used when we are moved to a new socket
*/
public void onNodeChange() {
Track track = getPlayingTrack();
AudioTrack track = getPlayingTrack();
if (track != null) {
playTrack(track);
}

}

@Override
public Track getPlayingTrack() {
public AudioTrack getPlayingTrack() {
return track;
}

@Override
public void playTrack(Track track) {
public void playTrack(AudioTrack track) {
playTrack(track, 0, 0);
}

@Override
public void playTrack(Track track, long startTime, long endTime) {
public void playTrack(AudioTrack track, long startTime, long endTime) {
JSONObject json = new JSONObject();
json.put("op", "play");
json.put("guildId", Long.toString(link.getGuildId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
package lavalink.client.player.event;

import lavalink.client.player.IPlayer;
import lavalink.client.player.track.Track;
import lavalink.client.player.track.TrackEndReason;
import lavalink.client.player.track.AudioTrack;
import lavalink.client.player.track.AudioTrackEndReason;

public class PlayerEventListenerAdapter implements IPlayerEventListener {

Expand All @@ -49,7 +49,7 @@ public void onPlayerResume(IPlayer player) {
* @param track Audio track that started
*/
@SuppressWarnings("unused")
public void onTrackStart(IPlayer player, Track track) {
public void onTrackStart(IPlayer player, AudioTrack track) {
// Adapter dummy method
}

Expand All @@ -59,7 +59,7 @@ public void onTrackStart(IPlayer player, Track track) {
* @param endReason The reason why the track stopped playing
*/
@SuppressWarnings("unused")
public void onTrackEnd(IPlayer player, Track track, TrackEndReason endReason) {
public void onTrackEnd(IPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
// Adapter dummy method
}

Expand All @@ -69,7 +69,7 @@ public void onTrackEnd(IPlayer player, Track track, TrackEndReason endReason) {
* @param exception The exception that occurred
*/
@SuppressWarnings("unused")
public void onTrackException(IPlayer player, Track track, Exception exception) {
public void onTrackException(IPlayer player, AudioTrack track, Exception exception) {
// Adapter dummy method
}

Expand All @@ -79,7 +79,7 @@ public void onTrackException(IPlayer player, Track track, Exception exception) {
* @param thresholdMs The wait threshold that was exceeded for this event to trigger
*/
@SuppressWarnings("unused")
public void onTrackStuck(IPlayer player, Track track, long thresholdMs) {
public void onTrackStuck(IPlayer player, AudioTrack track, long thresholdMs) {
// Adapter dummy method
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/lavalink/client/player/event/TrackEndEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@

package lavalink.client.player.event;

import lavalink.client.player.track.TrackEndReason;
import lavalink.client.player.track.AudioTrackEndReason;
import lavalink.client.player.IPlayer;
import lavalink.client.player.track.DefaultTrack;
import lavalink.client.player.track.DefaultAudioTrack;

public class TrackEndEvent extends PlayerEvent {

private final DefaultTrack track;
private final TrackEndReason reason;
private final DefaultAudioTrack track;
private final AudioTrackEndReason reason;

public TrackEndEvent(IPlayer player, DefaultTrack track, TrackEndReason reason) {
public TrackEndEvent(IPlayer player, DefaultAudioTrack track, AudioTrackEndReason reason) {
super(player);
this.track = track;
this.reason = reason;
}

public DefaultTrack getTrack() {
public DefaultAudioTrack getTrack() {
return this.track;
}

public TrackEndReason getReason() {
public AudioTrackEndReason getReason() {
return this.reason;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
package lavalink.client.player.event;

import lavalink.client.player.IPlayer;
import lavalink.client.player.track.DefaultTrack;
import lavalink.client.player.track.DefaultAudioTrack;

public class TrackExceptionEvent extends PlayerEvent {

private final DefaultTrack track;
private final DefaultAudioTrack track;
private final Exception exception;

public TrackExceptionEvent(IPlayer player, DefaultTrack track, Exception exception) {
public TrackExceptionEvent(IPlayer player, DefaultAudioTrack track, Exception exception) {
super(player);
this.track = track;
this.exception = exception;
}

public DefaultTrack getTrack() {
public DefaultAudioTrack getTrack() {
return this.track;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
package lavalink.client.player.event;

import lavalink.client.player.IPlayer;
import lavalink.client.player.track.DefaultTrack;
import lavalink.client.player.track.DefaultAudioTrack;

public class TrackStartEvent extends PlayerEvent {

private final DefaultTrack track;
private final DefaultAudioTrack track;

public TrackStartEvent(IPlayer player, DefaultTrack track) {
public TrackStartEvent(IPlayer player, DefaultAudioTrack track) {
super(player);
this.track = track;
}

public DefaultTrack getTrack() {
public DefaultAudioTrack getTrack() {
return this.track;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
package lavalink.client.player.event;

import lavalink.client.player.IPlayer;
import lavalink.client.player.track.DefaultTrack;
import lavalink.client.player.track.DefaultAudioTrack;

public class TrackStuckEvent extends PlayerEvent {

private final DefaultTrack track;
private final DefaultAudioTrack track;
private final long thresholdMs;

public TrackStuckEvent(IPlayer player, DefaultTrack track, long thresholdMs) {
public TrackStuckEvent(IPlayer player, DefaultAudioTrack track, long thresholdMs) {
super(player);
this.track = track;
this.thresholdMs = thresholdMs;
}

public DefaultTrack getTrack() {
public DefaultAudioTrack getTrack() {
return this.track;
}

Expand Down
Loading

0 comments on commit db7a0e0

Please sign in to comment.