0

SDカードに保存されているユーザーのビデオに関する情報を取得しようとしていますが、次の方法があります:

protected void addVideo () {
    cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            mediaColumns, null, null, null);

    if (cursor.moveToFirst()) {

        int i = 1;



        do {

            VideoItem newVVI = new VideoItem();
            int id = cursor.getInt(cursor
                    .getColumnIndex(MediaStore.Video.Media._ID));
            newVVI.idthumb = cursor.getString(cursor
                    .getColumnIndex(MediaStore.Video.Thumbnails._ID));
            Cursor thumbCursor = cr.query(
                    MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
                    thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID
                            + "=" + id, null, null);
            if (thumbCursor.moveToFirst()) {
                newVVI.thumbPath = thumbCursor.getString(thumbCursor
                        .getColumnIndex(MediaStore.Video.Thumbnails.DATA));

            }
            newVVI.filePath = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
            newVVI.title = cursor.getString(cursor
                    .getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
            try {
                newVVI.date = cursor.getString(cursor
                        .getColumnIndexOrThrow(MediaStore.Video.Media.DATE_TAKEN));
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                newVVI.date = "0";
            }
            try {
                newVVI.duration = cursor.getString(cursor
                        .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                newVVI.duration = "0";
            }
            try {
                newVVI.size = cursor.getString(cursor
                        .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                newVVI.size = "0";
            }
            try {
                newVVI.resolution = cursor.getString(cursor
                        .getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION));
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                newVVI.resolution = "0";
            }

            newVVI.mimeType = cursor
                    .getString(cursor
                            .getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));

            newVVI.id = Integer.toString(i);
            ITEMS.add(newVVI);
            ITEM_MAP.put(newVVI.id, newVVI);
            i++;


        } while (cursor.moveToNext());

        cursor.close();


    } else {
        Log.d("TEST", ": else);
    }



}

問題は、MediaStore.Video.Media.DATE_TAKEN、MediaStore.Video.Media.DURATION、MediaStore.Video.Media.SIZE、および MediaStore.Video.Media.RESOLUTION の場合、常に「0」になることです。 IllegalArgumentException.

なんで?

4

2 に答える 2

0

このコードは、1 つの特別なオーディオから情報を返します。すべてのオーディオまたはビデオを取得するための私の主な質問 whit while ステートメントに従って、それを変更できます。Mediastore.Video への応答で MediaStore.audio を変更する必要があります。

String name="";
String duration="";
String path="";
Log.d("Loading file: " + filepath,"");

        // This returns us content://media/external/videos/media (or something like that)
        // I pass in "external" because that's the MediaStore's name for the external
        // storage on my device (the other possibility is "internal")
Uri audiosUri = MediaStore.Audio.Media.getContentUri("external");

Log.d("audiosUri = " + audiosUri.toString(),"");

String[] projection = {MediaStore.Audio.AudioColumns.DATA,MediaStore.Audio.AudioColumns.DISPLAY_NAME,MediaStore.Audio.AudioColumns.DURATION};

// TODO This will break if we have no matching item in the MediaStore.
Cursor cursor = managedQuery(audiosUri, projection, MediaStore.Audio.AudioColumns.DATA + " LIKE ?", new String[] { filepath }, null);
cursor.moveToFirst();

path =cursor.getString( cursor.getColumnIndex(projection[0]));
name=cursor.getString( cursor.getColumnIndex(projection[1]));
int iduration = cursor.getColumnIndex(projection[2]);
duration=CalTotalTime(Integer.valueOf(iduration));
Log.d("pathhhhhhhhhhhhhhhhhh", path);
Log.d("nameeeeeeeeeeeeeeeeeeeeeee", name);
Log.d("duration", duration);

cursor.close();

このリンクも参照してください: mediastore でファイルから情報を取得する

于 2013-11-22T08:30:10.167 に答える
0

これがデフォルトであり、他の値に設定されていないため、値は 0 です。ビデオが SD カードにコピーされるとき、MediaStore はこれらの値を自動的に計算しません。

期間については、 MediaPlayerを使用してビデオをロードしてから、getDuration を呼び出すことができます。

于 2013-04-10T08:14:29.883 に答える