use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class SoundCloudAudioTrack method playFromIdentifier.
private void playFromIdentifier(HttpInterface httpInterface, String identifier, boolean recursion, LocalAudioTrackExecutor localExecutor) throws Exception {
SoundCloudM3uInfo m3uInfo = sourceManager.getFormatHandler().getM3uInfo(identifier);
if (m3uInfo != null) {
processDelegate(new SoundCloudM3uAudioTrack(trackInfo, httpInterface, m3uInfo), localExecutor);
return;
}
String mp3LookupUrl = sourceManager.getFormatHandler().getMp3LookupUrl(identifier);
if (mp3LookupUrl != null) {
String playbackUrl = SoundCloudHelper.loadPlaybackUrl(httpInterface, identifier.substring(2));
loadFromMp3Url(localExecutor, httpInterface, playbackUrl);
return;
}
if (!recursion) {
// Old "track ID" entry? Let's "load" it to get url.
AudioTrack track = sourceManager.loadFromTrackPage(trackInfo.uri);
playFromIdentifier(httpInterface, track.getIdentifier(), true, localExecutor);
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class RemoteNodeProcessor method startPlaying.
/**
* Start playing a track through this remote node.
* @param executor The executor of the track
*/
public void startPlaying(RemoteAudioTrackExecutor executor) {
AudioTrack track = executor.getTrack();
if (playingTracks.putIfAbsent(executor.getExecutorId(), executor) == null) {
long position = executor.getNextInputTimecode();
log.info("Sending request to play {} {} from position {}", track.getIdentifier(), executor.getExecutorId(), position);
queuedMessages.add(new TrackStartRequestMessage(executor.getExecutorId(), track.getInfo(), playerManager.encodeTrackDetails(track), executor.getVolume(), executor.getConfiguration(), position));
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class DefaultSoundCloudPlaylistLoader method loadPlaylistTracks.
protected List<AudioTrack> loadPlaylistTracks(HttpInterface httpInterface, JsonBrowser playlistData, Function<AudioTrackInfo, AudioTrack> trackFactory) throws IOException {
String playlistId = dataReader.readPlaylistIdentifier(playlistData);
List<String> trackIds = dataReader.readPlaylistTracks(playlistData).stream().map(dataReader::readTrackId).collect(Collectors.toList());
int numTrackIds = trackIds.size();
List<JsonBrowser> trackDataList = new ArrayList<>();
for (int i = 0; i < numTrackIds; i += 50) {
int last = Math.min(i + 50, numTrackIds);
List<String> trackIdSegment = trackIds.subList(i, last);
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(buildTrackListUrl(trackIdSegment)))) {
HttpClientTools.assertSuccessWithContent(response, "track list response");
JsonBrowser trackList = JsonBrowser.parse(response.getEntity().getContent());
trackDataList.addAll(trackList.values());
}
}
sortPlaylistTracks(trackDataList, trackIds);
int blockedCount = 0;
List<AudioTrack> tracks = new ArrayList<>();
for (JsonBrowser trackData : trackDataList) {
if (dataReader.isTrackBlocked(trackData)) {
blockedCount++;
} else {
try {
tracks.add(trackFactory.apply(dataReader.readTrackInfo(trackData, formatHandler.buildFormatIdentifier(formatHandler.chooseBestFormat(dataReader.readTrackFormats(trackData))))));
} catch (Exception e) {
log.error("In soundcloud playlist {}, failed to load track", playlistId, e);
}
}
}
if (blockedCount > 0) {
log.debug("In soundcloud playlist {}, {} tracks were omitted because they are blocked.", playlistId, blockedCount);
}
return tracks;
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class DefaultAudioPlayerManager method checkSourcesForItemOnce.
private AudioItem checkSourcesForItemOnce(AudioReference reference, AudioLoadResultHandler resultHandler, boolean[] reported) {
for (AudioSourceManager sourceManager : sourceManagers) {
if (reference.containerDescriptor != null && !(sourceManager instanceof ProbingAudioSourceManager)) {
continue;
}
AudioItem item = sourceManager.loadItem(this, reference);
if (item != null) {
if (item instanceof AudioTrack) {
log.debug("Loaded a track with identifier {} using {}.", reference.identifier, sourceManager.getClass().getSimpleName());
reported[0] = true;
resultHandler.trackLoaded((AudioTrack) item);
} else if (item instanceof AudioPlaylist) {
log.debug("Loaded a playlist with identifier {} using {}.", reference.identifier, sourceManager.getClass().getSimpleName());
reported[0] = true;
resultHandler.playlistLoaded((AudioPlaylist) item);
}
return item;
}
}
return null;
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class StreamAudioPlayer method startTrack.
@Override
public boolean startTrack(AudioTrack track, boolean noInterrupt) {
if (track == null) {
stopTrack();
} else {
synchronized (lock) {
AudioTrack previousTrack = getPlayingTrack();
if (noInterrupt && previousTrack != null) {
return false;
}
if (previousTrack != null) {
if (streamCursor == null) {
fallback.stopTrack();
} else {
detachStream();
}
dispatchEvent(new TrackEndEvent(this, previousTrack, REPLACED));
}
streamCursor = manager.openTrack(track, detachListener);
if (streamCursor == null) {
fallback.startTrack(track, false);
}
dispatchEvent(new TrackStartEvent(this, track));
}
}
return true;
}
Aggregations