【问题标题】:How to get all videos on Android device如何在 Android 设备上获取所有视频
【发布时间】:2012-05-08 17:54:07
【问题描述】:

如何获取所有视频列表及其路径,这些视频可以在安装了我的应用的 Android 设备上找到?

编辑: 我正在尝试制作一个简单的视频播放器,因此想法是显示设备上可以找到的所有视频并在列表项单击时播放。 唯一的问题是我不知道如何获取有关视频的信息,所以如果有人可以帮助我,我将非常感激。

【问题讨论】:

  • 我什么都没试过,真的不知道从哪里开始..
  • 我在互联网上真的找不到任何可以帮助我的东西,所以我还没有尝试过任何东西。现在我完成了应用程序的其余部分,但只是错过了要播放的选择视频。
  • 我在 Related 栏中找到了这个,在那边 --> stackoverflow.com/q/2911124/1267661 还有更多有用的链接,还有 Preet Sangha 的。祝你好运!
  • 这很有帮助 -> stackoverflow.com/q/2911124/1267661 感谢您的帮助,抱歉重复发布。

标签: android


【解决方案1】:

如果有人仍在寻找答案,请尝试此方法。此方法将返回所有媒体的路径列表。

public ArrayList<String> getAllMedia() {
    HashSet<String> videoItemHashSet = new HashSet<>();
    String[] projection = { MediaStore.Video.VideoColumns.DATA ,MediaStore.Video.Media.DISPLAY_NAME};
    Cursor cursor = getContext().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
    try {
        cursor.moveToFirst();
        do{
            videoItemHashSet.add((cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA))));
        }while(cursor.moveToNext());

        cursor.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ArrayList<String> downloadedList = new ArrayList<>(videoItemHashSet);
    return downloadedList;
}

【讨论】:

  • 如果文件夹以编程方式创建 stackoverflow.com/questions/48934159/…请检查此
【解决方案2】:

试试下面的代码。

private void getVideoList() {
    Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    String[] projection = {MediaStore.Video.VideoColumns.DATA};
    Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
    ArrayList<String> pathArrList = new ArrayList<>();
    if (cursor != null) {
        while (cursor.moveToNext()) {
            pathArrList.add(cursor.getString(0));
        }
        cursor.close();
    }
    Log.e("all path",pathArrList.toString());
}

【讨论】:

  • 花费太多时间来迭代视频。如何加快速度?我想从设备获取所有视频路径
【解决方案3】:
String[] projection = { MediaStore.Video.Media._ID};
Cursor cursor = new CursorLoader(contexts, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, 
            null, // Return all rows
            null, null).loadInBackground();

获得光标后,您可以对其进行迭代并使用视频 ID 获取所有视频。

【讨论】:

猜你喜欢
  • 2014-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 2017-05-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多