private AudioTrack decodeTrackDetails(AudioTrackInfo trackInfo, DataInput input) throws IOException { String sourceName = input.readUTF(); for (AudioSourceManager sourceManager : sourceManagers) { if (sourceName.equals(sourceManager.getSourceName())) { return sourceManager.decodeTrack(trackInfo, input); } } return null; }
@SuppressWarnings("unchecked") @Override public void on(Context context) { if (!sourceManagersMessage.isPresent()) { try { Field field = DefaultAudioPlayerManager.class.getDeclaredField("sourceManagers"); field.setAccessible(true); sourceManagersMessage = Optional.of(((List<AudioSourceManager>) field.get(playerManager)) .stream() .map(manager -> manager.getSourceName().toLowerCase()) .collect(Collectors.joining(", "))); } catch (NoSuchFieldException | IllegalAccessException e) { LOGGER.error("error getting available music providers", e); return; } } context.reply("Available music providers: %s", sourceManagersMessage.get()); } }
private void encodeTrackDetails(AudioTrack track, DataOutput output) throws IOException { AudioSourceManager sourceManager = track.getSourceManager(); output.writeUTF(sourceManager.getSourceName()); sourceManager.encodeTrack(track, output); }
@Override public void trackLoaded(AudioTrack track) { if (track.getSourceManager().getSourceName().equals("youtube")) { OMusic rec = CMusic.findByYoutubeId(track.getInfo().identifier); if (rec.id == 0 || rec.duration == 0) { rec.artist = track.getInfo().author; rec.duration = (int) (track.getInfo().length / 1000L); rec.youtubeTitle = track.getInfo().title; CMusic.update(rec); } } scheduler.queue(new QueuedAudioTrack(trackToAdd.requestedBy, track)); startPlaying(); }