Пример #1
0
  @Override
  protected void update() {
    starButton.setVisibility(
        (Util.isOffline(getContext()) || !song.isStarred()) ? View.GONE : View.VISIBLE);
    DownloadService downloadService = DownloadServiceImpl.getInstance();
    if (downloadService == null) {
      return;
    }

    DownloadFile downloadFile = downloadService.forSong(song);
    File partialFile = downloadFile.getPartialFile();

    int leftImage = 0;
    int rightImage = 0;

    if (downloadFile.isWorkDone()) {
      leftImage = downloadFile.shouldSave() ? R.drawable.saved : R.drawable.downloaded;
    }

    if (downloadFile.isDownloading()
        && !downloadFile.isDownloadCancelled()
        && partialFile.exists()) {
      statusTextView.setText(Util.formatLocalizedBytes(partialFile.length(), getContext()));
      rightImage = R.drawable.downloading;
    } else {
      statusTextView.setText(null);
    }
    statusTextView.setCompoundDrawablesWithIntrinsicBounds(leftImage, 0, rightImage, 0);

    boolean playing = downloadService.getCurrentPlaying() == downloadFile;
    if (playing) {
      titleTextView.setCompoundDrawablesWithIntrinsicBounds(
          R.drawable.stat_notify_playing, 0, 0, 0);
    } else {
      titleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    }
  }
Пример #2
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();
  }