io.vov.vitamio.utils.FileUtils Java Examples

The following examples show how to use io.vov.vitamio.utils.FileUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaMetadataRetriever.java    From MyHearts with Apache License 2.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
Example #2
Source File: MediaMetadataRetriever.java    From BambooPlayer with Apache License 2.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
Example #3
Source File: MediaPlayer.java    From BambooPlayer with Apache License 2.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  setDataSource(uri.toString(), headers);
}
 
Example #4
Source File: MediaMetadataRetriever.java    From Vitamio with Apache License 2.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
Example #5
Source File: MediaPlayer.java    From Vitamio with Apache License 2.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  setDataSource(uri.toString(), headers);
}
 
Example #6
Source File: MediaMetadataRetriever.java    From react-native-android-vitamio with MIT License 6 votes vote down vote up
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
Example #7
Source File: MediaPlayer.java    From react-native-android-vitamio with MIT License 6 votes vote down vote up
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  setDataSource(uri.toString(), headers);
}
 
Example #8
Source File: MediaMetadataRetriever.java    From NetEasyNews with GNU General Public License v3.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
Example #9
Source File: MediaPlayer.java    From NetEasyNews with GNU General Public License v3.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  setDataSource(uri.toString(), headers);
}
 
Example #10
Source File: MediaMetadataRetriever.java    From video-player with MIT License 6 votes vote down vote up
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
Example #11
Source File: MediaPlayer.java    From video-player with MIT License 6 votes vote down vote up
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  setDataSource(uri.toString(), headers);
}
 
Example #12
Source File: MediaMetadataRetriever.java    From HPlayer with Apache License 2.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
    SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
  setDataSource(uri.toString());
  return;
}
 
Example #13
Source File: MediaPlayer.java    From HPlayer with Apache License 2.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  setDataSource(uri.toString(), headers);
}
 
Example #14
Source File: MediaPlayer.java    From MyHearts with Apache License 2.0 6 votes vote down vote up
public void setDataSource(Context context, Uri uri, Map<String, String> headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
  if (context == null || uri == null)
    throw new IllegalArgumentException();
  String scheme = uri.getScheme();
  if (scheme == null || scheme.equals("file")) {
    setDataSource(FileUtils.getPath(uri.toString()));
    return;
  }

  try {
    ContentResolver resolver = context.getContentResolver();
    mFD = resolver.openAssetFileDescriptor(uri, "r");
    if (mFD == null)
      return;
    setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
    return;
  } catch (Exception e) {
    closeFD();
  }
  setDataSource(uri.toString(), headers);
}
 
Example #15
Source File: MediaScanner.java    From video-player with MIT License 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example #16
Source File: MediaScanner.java    From NetEasyNews with GNU General Public License v3.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example #17
Source File: MediaScanner.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example #18
Source File: MediaScanner.java    From react-native-android-vitamio with MIT License 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example #19
Source File: MediaScanner.java    From Vitamio with Apache License 2.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example #20
Source File: MediaScanner.java    From MyHearts with Apache License 2.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}
 
Example #21
Source File: MediaScanner.java    From BambooPlayer with Apache License 2.0 4 votes vote down vote up
private void prescan(String filePath) throws RemoteException {
  mProvider = mContext.getContentResolver().acquireContentProviderClient(MediaStore.AUTHORITY);
  Cursor c = null;
  String where = null;
  String[] selectionArgs = null;

  if (mFileCache == null)
    mFileCache = new HashMap<String, FileCacheEntry>();
  else
    mFileCache.clear();

  try {
    if (filePath != null) {
      where = Video.Media.DATA + "=?";
      selectionArgs = new String[]{filePath};
    }

    c = mProvider.query(Video.Media.CONTENT_URI, VIDEO_PROJECTION, where, selectionArgs, null);
    if (c != null) {
      try {
        while (c.moveToNext()) {
          long rowId = c.getLong(ID_VIDEO_COLUMN_INDEX);
          String path = c.getString(PATH_VIDEO_COLUMN_INDEX);
          long lastModified = c.getLong(DATE_MODIFIED_VIDEO_COLUMN_INDEX);
          if (path.startsWith("/")) {
            File tempFile = new File(path);
            if (!TextUtils.isEmpty(filePath) && !tempFile.exists()) {
              mProvider.delete(Video.Media.CONTENT_URI, where, selectionArgs);
              return;
            }
            path = FileUtils.getCanonical(tempFile);
            String key = mCaseInsensitivePaths ? path.toLowerCase() : path;
            mFileCache.put(key, new FileCacheEntry(Video.Media.CONTENT_URI, rowId, path, lastModified));
          }
        }
      } finally {
        c.close();
        c = null;
      }
    }
  } finally {
    if (c != null) {
      c.close();
    }
  }
}