/**
   * Download .zip file specified by url, then unzip it to a folder in external storage.
   *
   * @param url
   */
  private void downloadAllAssets(String url) {
    // File zipDir = ExternalStorage.get
    // Temp folder for holding asset during download
    File zipDir = ExternalStorage.getSDCacheDir(this, "tmp");
    // File path to store .zip file before unzipping
    File zipFile = new File(zipDir.getPath() + "/temp.zip");
    // Folder to hold unzipped output
    File outputDir = ExternalStorage.getSDCacheDir(this, "unzipped");

    try {
      DownloadFile.download(url, zipFile, zipDir);
      unzipFile(zipFile, outputDir);
    } finally {
      zipFile.delete();
    }
  }
Exemplo n.º 2
0
  protected synchronized void checkDownloads() {

    if (!Util.isExternalStoragePresent() || !lifecycleSupport.isExternalStorageAvailable()) {
      return;
    }

    if (shufflePlay) {
      checkShufflePlay();
    }

    if (jukeboxEnabled || !Util.isNetworkConnected(this)) {
      return;
    }

    if (downloadList.isEmpty()) {
      return;
    }

    // Need to download current playing?
    if (currentPlaying != null
        && currentPlaying != currentDownloading
        && !currentPlaying.isCompleteFileAvailable()) {

      // Cancel current download, if necessary.
      if (currentDownloading != null) {
        currentDownloading.cancelDownload();
      }

      currentDownloading = currentPlaying;
      currentDownloading.download();
      cleanupCandidates.add(currentDownloading);
    }

    // Find a suitable target for download.
    else if (currentDownloading == null
        || currentDownloading.isWorkDone()
        || currentDownloading.isFailed()) {

      int n = size();
      if (n == 0) {
        return;
      }

      int preloaded = 0;

      int start = currentPlaying == null ? 0 : getCurrentPlayingIndex();
      int i = start;
      do {
        DownloadFile downloadFile = downloadList.get(i);
        if (!downloadFile.isWorkDone()) {
          if (downloadFile.shouldSave() || preloaded < Util.getPreloadCount(this)) {
            currentDownloading = downloadFile;
            currentDownloading.download();
            cleanupCandidates.add(currentDownloading);
            break;
          }
        } else if (currentPlaying != downloadFile) {
          preloaded++;
        }

        i = (i + 1) % n;
      } while (i != start);
    }

    // Delete obsolete .partial and .complete files.
    cleanup();
  }