Пример #1
0
  @Override
  public List<Serializable> getObjects(
      MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
    List<PodcastChannel> channels = musicService.getPodcastChannels(refresh, context, listener);

    if (!Util.isOffline(context) && ServerInfo.hasNewestPodcastEpisodes(context)) {
      try {
        newestEpisodes = musicService.getNewestPodcastEpisodes(10, context, listener);

        for (MusicDirectory.Entry entry : newestEpisodes.getChildren()) {
          for (PodcastChannel channel : channels) {
            if (channel.getId().equals(entry.getParent())) {
              PodcastEpisode episode = (PodcastEpisode) entry;

              // Update with information normally done in PodcastEntryParser
              episode.setArtist(channel.getName());
              episode.setCoverArt(channel.getCoverArt());
              episode.setPath(FileUtil.getPodcastPath(context, episode));
              break;
            }
          }
        }
      } catch (Exception e) {
        Log.e(TAG, "Failed to download newest episodes", e);
        newestEpisodes = null;
      }
    } else {
      newestEpisodes = null;
    }

    List<Serializable> serializableList = new ArrayList<>();
    serializableList.addAll(channels);

    return serializableList;
  }
Пример #2
0
  private void showAboutDialog() {
    try {
      File rootFolder = FileUtil.getMusicDirectory(context);
      StatFs stat = new StatFs(rootFolder.getPath());
      long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize();
      long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();

      String msg =
          getResources()
              .getString(
                  R.string.main_about_text,
                  context
                      .getPackageManager()
                      .getPackageInfo(context.getPackageName(), 0)
                      .versionName,
                  Util.formatBytes(FileUtil.getUsedSize(context, rootFolder)),
                  Util.formatBytes(Util.getCacheSizeMB(context) * 1024L * 1024L),
                  Util.formatBytes(bytesAvailableFs),
                  Util.formatBytes(bytesTotalFs));
      Util.info(context, R.string.main_about_title, msg);
    } catch (Exception e) {
      Util.toast(context, "Failed to open dialog");
    }
  }
Пример #3
0
  public void displaySongInfo(final MusicDirectory.Entry song) {
    Integer bitrate = null;
    String format = null;
    long size = 0;
    try {
      DownloadFile downloadFile = new DownloadFile(SubsonicTabActivity.this, song, false);
      File file = downloadFile.getCompleteFile();
      if (file.exists()) {
        MediaMetadataRetriever metadata = new MediaMetadataRetriever();
        metadata.setDataSource(file.getAbsolutePath());
        String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
        bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
        format = FileUtil.getExtension(file.getName());
        size = file.length();

        if (Util.isOffline(SubsonicTabActivity.this)) {
          song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
          String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
          song.setYear(Integer.parseInt((year != null) ? year : "0"));
        }
      }
    } catch (Exception e) {
      Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver");
    }

    String msg = "";
    if (!song.isVideo()) {
      msg += "Artist: " + song.getArtist() + "\nAlbum: " + song.getAlbum();
    }
    if (song.getTrack() != null && song.getTrack() != 0) {
      msg += "\nTrack: " + song.getTrack();
    }
    if (song.getGenre() != null && !"".equals(song.getGenre())) {
      msg += "\nGenre: " + song.getGenre();
    }
    if (song.getYear() != null && song.getYear() != 0) {
      msg += "\nYear: " + song.getYear();
    }
    if (!Util.isOffline(SubsonicTabActivity.this)) {
      msg += "\nServer Format: " + song.getSuffix();
      if (song.getBitRate() != null && song.getBitRate() != 0) {
        msg += "\nServer Bitrate: " + song.getBitRate() + " kpbs";
      }
    }
    if (format != null && !"".equals(format)) {
      msg += "\nCached Format: " + format;
    }
    if (bitrate != null && bitrate != 0) {
      msg += "\nCached Bitrate: " + bitrate + " kpbs";
    }
    if (size != 0) {
      msg += "\nSize: " + Util.formatBytes(size);
    }
    if (song.getDuration() != null && song.getDuration() != 0) {
      msg += "\nLength: " + Util.formatDuration(song.getDuration());
    }

    new AlertDialog.Builder(this)
        .setIcon(android.R.drawable.ic_dialog_alert)
        .setTitle(song.getTitle())
        .setMessage(msg)
        .show();
  }