示例#1
0
  private synchronized void compareVideoFiles() {
    //		Log.i("Test", "----------compareVideoFiles");
    if (null == mVideoCategory) {
      return;
    }

    String volumeName = "external";
    Uri uri = Video.Media.getContentUri(volumeName);

    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          VideoColumns.DURATION,
          MediaColumns.MIME_TYPE
        };
    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_VIDEO), null, null);

      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }
      compareFile(cur, mVideoCategory, mDeletedVideoList, TYPE_VIDEO);
    } catch (SQLiteException ex) {
      ex.printStackTrace();
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }
示例#2
0
  private void registerReceiver() {
    ContentResolver resolver = mContext.getContentResolver();
    String volumeName = "external";
    Uri uriAudio = Audio.Media.getContentUri(volumeName);
    mAudioObv = new ContentObserverAudio();
    resolver.registerContentObserver(uriAudio, true, mAudioObv);

    Uri uriImages = Images.Media.getContentUri(volumeName);
    mImagesObv = new ContentObserverImage();
    resolver.registerContentObserver(uriImages, true, mImagesObv);

    Uri uriVideo = Video.Media.getContentUri(volumeName);
    mVideoObv = new ContentObserverVideo();
    resolver.registerContentObserver(uriVideo, true, mVideoObv);

    mMediaScanReceiver = new MediaScanReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    filter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    filter.addDataScheme("file");
    mContext.registerReceiver(mMediaScanReceiver, filter);
  }
示例#3
0
  /**
   * 获取文件的MimeType
   *
   * @param dbId
   * @param type
   * @return
   */
  public String getMimeType(int dbId, int type) {
    String volumeName = "external";
    String selection = BaseColumns._ID + "='" + dbId + "'";
    String[] columns = new String[] {MediaColumns.MIME_TYPE};
    Uri uri = null;
    switch (type) {
      case TYPE_IMAGE:
        uri = Images.Media.getContentUri(volumeName);
        break;
      case TYPE_AUDIO:
        uri = Audio.Media.getContentUri(volumeName);
        break;
      case TYPE_VIDEO:
        uri = Video.Media.getContentUri(volumeName);
        break;
      default:
        break;
    }
    if (uri == null) {
      return null;
    }
    Cursor cur = null;
    try {
      cur = mContext.getContentResolver().query(uri, columns, selection, null, null);
      if (null == cur) {
        return null;
      }

      if (!cur.moveToFirst()) {
        return null;
      }
      return MediaDbUtil.getString(cur, MediaColumns.MIME_TYPE);
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }
  public void refreshCategoryInfo() {
    // clear
    for (FileCategory fc : sCategories) {
      setCategoryInfo(fc, 0, 0);
    }

    // query database
    String volumeName = "external";

    Uri uri = Audio.Media.getContentUri(volumeName);
    refreshMediaCategory(FileCategory.Music, uri);

    uri = Video.Media.getContentUri(volumeName);
    refreshMediaCategory(FileCategory.Video, uri);

    uri = Images.Media.getContentUri(volumeName);
    refreshMediaCategory(FileCategory.Picture, uri);

    uri = Files.getContentUri(volumeName);
    refreshMediaCategory(FileCategory.Theme, uri);
    refreshMediaCategory(FileCategory.Doc, uri);
    refreshMediaCategory(FileCategory.Zip, uri);
    refreshMediaCategory(FileCategory.Apk, uri);
  }
 private Uri getContentUriByCategory(FileCategory cat) {
   Uri uri;
   String volumeName = "external";
   switch (cat) {
     case Theme:
     case Doc:
     case Zip:
     case Apk:
       uri = Files.getContentUri(volumeName);
       break;
     case Music:
       uri = Audio.Media.getContentUri(volumeName);
       break;
     case Video:
       uri = Video.Media.getContentUri(volumeName);
       break;
     case Picture:
       uri = Images.Media.getContentUri(volumeName);
       break;
     default:
       uri = null;
   }
   return uri;
 }
示例#6
0
  public synchronized void initVideo() {
    if (null == mVideoCategory) {
      mVideoCategory = new ConcurrentHashMap<String, Category>();
    }
    mVideoCategory.clear();

    String volumeName = "external";
    Uri uri = Video.Media.getContentUri(volumeName);

    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          VideoColumns.DURATION,
          MediaColumns.MIME_TYPE
        };
    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_AUDIO), null, null);

      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }

      do {
        VideoFile file = VideoFile.getInfo(cur);
        if (null == file) {
          continue;
        }

        if (mVideoCategory.containsKey(file.filePath)) {
          Category category = mVideoCategory.get(file.filePath);
          category.addFile(file);
        } else {
          Category category = new Category();
          category.filePath = file.filePath;
          category.uri = category.filePath;
          category.init();
          category.addFile(file);
          mVideoCategory.put(file.filePath, category);
        }
      } while (cur.moveToNext());
    } catch (SQLiteException e) {
      Log.e("FileEngine", "init video error");
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }