0

我正在创建一个应用程序,您可以在其中使用 Media App Architecture播放所有 .wav 文件。因此,当用户在听歌曲时,内部应用程序正在创建歌曲的反向文件并将其保存在特定路径中。它工作正常。(“/storage/emulated/0/VoiceRecorder/reverse-finish.wav”)。

但是当我想从特定的 URI 中获取 MediaMetadataCompat 时,它返回 null。这是代码:

    public static MediaMetadataCompat getMediaMetadataFromFilePath(Context context,
                                                                   Uri path) {
        String[] projection = {
                MediaStore.Audio.Media._ID,
                MediaStore.Audio.Media.DISPLAY_NAME,
                MediaStore.Audio.Media.TITLE,
                MediaStore.Audio.Media.DURATION,
                MediaStore.Audio.Media.DATA
        };
        Cursor audioCursor = context.getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                projection,
                MediaStore.Audio.Media._ID + " = ?",
                new String[]{path.getPath()},
                "");

        if (audioCursor == null) {
            return null;
        }
        audioCursor.moveToFirst();
        int mediaId = audioCursor.getColumnIndexOrThrow(
                MediaStore.Audio.Media._ID);
        int name = audioCursor.getColumnIndexOrThrow(
                MediaStore.Audio.Media.DISPLAY_NAME);
        int duration = audioCursor.getColumnIndexOrThrow(
                MediaStore.Audio.Media.DURATION);
        int title = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
        int data = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
        String id = audioCursor.getString(mediaId);
        MediaMetadataCompat media = createMediaMetadataCompat(
                id, audioCursor.getString(title),
                null, null, null,
                audioCursor.getLong(duration), TimeUnit.SECONDS,
                audioCursor.getString(name), 0, null,
                audioCursor.getString(data));
        return media;
    }

你能帮忙看看这里有什么问题吗?

4

0 回答 0