@Override public void previous() { log.log(LogType.PLAYER, "previous"); if (previousHandler != null) { previousHandler.run(); } else if (currentPlaylist != null && currentTrack != null) { int current = currentPlaylist.indexOf(currentTrack); if (current > 1) { open(currentPlaylist.get(--current)); } } }
@Override public void next() { log.log(LogType.PLAYER, "next"); if (nextHandler != null) { nextHandler.run(); } else if (currentPlaylist != null && currentTrack != null) { if (shuffle) { open(currentPlaylist.get((int) (Math.random() * currentPlaylist.size()))); } else { if (repeat) { open(currentPlaylist.get(playlistPosition)); } else if (currentPlaylist.size() > playlistPosition + 1) { open(currentPlaylist.get(++playlistPosition)); } else { // try to load new entries currentPlaylist.loadNextEntries(); // TODO: create temp listener try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } if (currentPlaylist.size() > playlistPosition + 1) { open(currentPlaylist.get(++playlistPosition)); } else { log.log(LogType.PLAYER, "end of list"); } } } } }
public void openAndSeek(PagedList<PagedListEntry> list, int i, double s) { // if track is already playing, just seek if (list.get(i) == currentTrack) { seek(new Duration(player.getTotalDuration().toMillis() * s)); } else { open(list, i); // wait for the player to load the meta data player.setOnPlaying(() -> seek(new Duration(player.getTotalDuration().toMillis() * s))); } }
public void open(PagedListEntry entry) { try { if (MediaManager.canPlayProtocol("https")) BackgroundLoader.addTaskWithTimeout( () -> { if (entry instanceof PlayList) { // expand inner playlists currentPlaylist.remove(entry); PagedList<PagedListEntry> innerPlaylist = ((PlayList) entry).getTrackList(); currentPlaylist.addAll(playlistPosition, innerPlaylist); currentTrack = (Track) currentPlaylist.get(++playlistPosition); } else { currentTrack = (Track) entry; } String url = currentTrack.getStreamURL(); currentMedia = new Media(url); stop(); currentTrack.getWaveform().resetProgress(); player = new MediaPlayer(currentMedia); player.volumeProperty().bindBidirectional(volumeSliderProb); player.setOnEndOfMedia(this::next); // TODO: append listener to new player player.setAudioSpectrumListener(audioSpectrumListener); player.play(); isPlaying = true; UIManager.setTrackForPlayerUI(currentTrack, currentPlaylist); UIManager.setPlayPauseIcon(isPlaying); }, 3 * 1000); } catch (NoSuchMethodError error) { // the support came together with that method String version = com.sun.javafx.runtime.VersionInfo.getRuntimeVersion(); log.log(LogType.PLAYER, "JavaFx version does not support https protocol"); log.log(LogType.PLAYER, "Min version = 8.0.72. Current version " + version); } }
public void open(PagedList<PagedListEntry> playlist, int startIndex) { currentPlaylist = playlist; playlistPosition = startIndex; open(currentPlaylist.get(startIndex)); }