Esempio n. 1
0
 // @TargetApi(11)
 private void calculateDuration(ContentValues map) throws IOException {
   if (Utils.isGingerBreadMROrLater()) {
     File videoFile = fileFromResourceMap(map);
     MediaMetadataRetriever mmr = new MediaMetadataRetriever();
     mmr.setDataSource(videoFile.toString());
     String duration = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
     if (!TextUtils.isEmpty(duration)) {
       map.put(Resources.DURATION, Integer.valueOf(duration));
     }
     mmr.release();
   }
 }
Esempio n. 2
0
  private void informMediaScanner(ContentValues map) throws IOException {
    final File videoFile = fileFromResourceMap(map);

    String dir = (String) map.get(Resources.DIRECTORY);
    if (VizUtils.isPublicDir(dir)) {
      Thread t =
          new Thread("AddVideoToGallery") {
            @Override
            public void run() {
              VizUtils.informMediaScanner(videoFile.toString());
            }
          };
      Utils.threadStart(t, "Failed to add video to gallery");
    }
  }
Esempio n. 3
0
  private void startDownload(Resource resource) {
    mConfirmationInProgress = false;

    ActivityDelegate ad = getActivityDelegate();
    if (ad == null) {
      return;
    }

    resource.setDownloadDirectory(VizUtils.getDownloadDir());

    // check download directory in case sd card or whatever has been
    // unmounted and we can no longer write to it.
    File directory = resource.getDownloadDirectory();
    if (!Utils.directoryCreate(directory)) {
      new AlertDialog.Builder(ad)
          .setIcon(R.drawable.ic_launcher)
          .setTitle(VizApp.getResString(R.string.download_failed))
          .setMessage(VizApp.getResString(R.string.storage_error))
          .setNeutralButton(R.string.ok, null)
          .create()
          .show();
      return;
    }

    Uri uri =
        VizApp.getResolver().insert(VizContract.Downloads.CONTENT_URI, resource.toContentValues());
    if (uri == null) {
      Log.e("Could not add download to database error");
      Toast.makeText(
              VizApp.getContext(),
              VizApp.getResString(R.string.database_access_error),
              Toast.LENGTH_LONG)
          .show();
      return;
    }

    Log.d("(uri=" + uri + ")");

    resource.setDownloadUri(uri);

    Downloads downloads = ad.getDownloadsFragment();
    downloads.queue(resource);
  }