示例#1
0
 @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");
         }
       }
     }
   }
 }
示例#2
0
 @Override
 public void play() {
   if (player != null) {
     if (isPlaying) {
       player.pause();
       isPlaying = false;
       log.log(LogType.PLAYER, "Pause");
     } else {
       player.play();
       isPlaying = true;
       log.log(LogType.PLAYER, "Play");
     }
     UIManager.setPlayPauseIcon(isPlaying);
   }
 }
示例#3
0
  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);
    }
  }
示例#4
0
 @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));
     }
   }
 }
示例#5
0
 @Override
 public void pause() {
   log.log(LogType.PLAYER, "pause");
   player.pause();
 }
示例#6
0
 @Override
 public void toggleShuffle() {
   log.log(LogType.PLAYER, "toggleShuffle");
   shuffle = !shuffle;
 }
示例#7
0
 @Override
 public void setMediaPausedListener(MediaEventListener listener) {
   log.log(LogType.PLAYER, "setMediaPausedListener");
   player.setOnPaused(listener::mediaEvent);
 }
示例#8
0
 @Override
 public void toggleRepeat() {
   log.log(LogType.PLAYER, "toggleRepeat");
   repeat = !repeat;
 }