public void stopSingleSongs() {
   for (Entry<Song, PlayerController> entry : singleSongPlayers.entrySet()) {
     PlayerController controller = entry.getValue();
     controller.close(true);
   }
   singleSongPlayers.clear();
 }
  private PlayerController createNewStationPlayer(byte type, short id) {

    // voice players are handled as stations but not as such in database
    if (!Client.database.hasStation(type, id) && type != GlobalConstants.TYPE_VOICE) {
      return null;
    }

    App.logger.d("Creating new player. Type: " + type + " id: " + id, null);

    PlayerController controller = null;

    Station station = Client.database.getStation(type, id);
    ConcurrentHashMap<Short, PlayerController> map = getStationPlayerMap(type);
    if (map != null) {
      if (station == null && type == GlobalConstants.TYPE_VOICE) {
        controller = new VoicePlayer(type, id);

      } else if (station != null) {
        controller = new StationPlayer(type, id);
      }

      map.put(id, controller);
    }

    if (controller != null) {
      // start the player
      controller.start();
    } else {
      App.logger.d("Failed to create new player. Type: " + type + " id: " + id, null);
    }

    return controller;
  }
  public void playSingleSong(Song song) {
    if (singleSongPlayers.containsKey(song)) {
      return;
    }
    // TODO: add priority to single songs
    PlayerController controller = new SingleSongPlayer(song, 1);
    controller.start();

    singleSongPlayers.put(song, controller);
  }
  public void updateStationPlayer(byte type, short id, double dist) {
    PlayerController controller = getStationPlayer(type, id);
    if (controller == null) {
      Station station = Client.database.getStation(type, id);
      if (station == null || (station.getSongs().isEmpty()) || Client.database.isMuted(type, id)) {
        return;
      }
      controller = createNewStationPlayer(type, id);
      if (controller == null) {
        return;
      }
    }
    if (type == GlobalConstants.TYPE_BOX) {
      int range = Client.database.getStation(GlobalConstants.TYPE_BOX, id).getRange();
      byte volumePercent = (byte) (100 - (dist / range) * 100);
      if (volumePercent >= 0) {
        controller.allowPlayback();
        volumeManager.setPlayerVolume(controller, volumePercent);
      } else {
        volumeManager.setPlayerVolume(controller, (byte) 0);
      }

    } else if (type == GlobalConstants.TYPE_AREA) {
      int fadeout = Client.database.getStation(GlobalConstants.TYPE_AREA, id).getRange();
      if (dist >= 0) {
        controller.allowPlayback();
        if (fadeout > 0 && dist < fadeout) {
          byte volumePercent = (byte) ((100.0 / fadeout) * dist);
          volumeManager.setPlayerVolume(controller, volumePercent);
        } else {
          volumeManager.setPlayerVolume(controller, (byte) 100);
        }
      } else {
        volumeManager.setPlayerVolume(controller, (byte) 0);
      }
    } else {
      volumeManager.setPlayerVolume(controller, (byte) 100);
    }
  }
 public void stopSingleSongPlayer(Song song) {
   PlayerController controller = singleSongPlayers.get(song);
   if (controller != null) {
     controller.close(false);
   }
 }
 public void stopStationPlayer(final byte type, final short id, boolean preventRestart) {
   PlayerController controller = getStationPlayer(type, id);
   if (controller != null) {
     controller.close(preventRestart);
   }
 }