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; }
private void encodeTrackDetails(AudioTrack track, DataOutput output) throws IOException { AudioSourceManager sourceManager = track.getSourceManager(); output.writeUTF(sourceManager.getSourceName()); sourceManager.encodeTrack(track, output); }
@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 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; }
private AudioTrackExecutor createExecutorForTrack(InternalAudioTrack track, AudioConfiguration configuration, AudioPlayerOptions playerOptions) { AudioSourceManager sourceManager = track.getSourceManager(); if (remoteNodeManager.isEnabled() && sourceManager != null && sourceManager.isTrackEncodable(track)) { return new RemoteAudioTrackExecutor(track, configuration, remoteNodeManager, playerOptions.volumeLevel); } else { AudioTrackExecutor customExecutor = track.createLocalExecutor(this); if (customExecutor != null) { return customExecutor; } else { int bufferDuration = Optional.ofNullable(playerOptions.frameBufferDuration.get()).orElse(frameBufferDuration); return new LocalAudioTrackExecutor(track, configuration, playerOptions, useSeekGhosting, bufferDuration); } } }
@Override public void shutdown() { remoteNodeManager.shutdown(true); garbageCollectionMonitor.disable(); lifecycleManager.shutdown(); for (AudioSourceManager sourceManager : sourceManagers) { sourceManager.shutdown(); } ExecutorTools.shutdownExecutor(trackPlaybackExecutorService, "track playback"); ExecutorTools.shutdownExecutor(trackInfoExecutorService, "track info"); ExecutorTools.shutdownExecutor(scheduledExecutorService, "scheduled operations"); }
@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(); }