1

I'm creating an application where you can play all .wav files using the Media App Architecture. So while user is listening a song, internally app is creating the reverse file of the song and save it in an specific path. It's working fine. ("/storage/emulated/0/VoiceRecorder/reverse-finish.wav").

But when I want to get MediaMetadataCompat from the specific URI, it return null. This is the code:

    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;
    }

Can you help what's wrong here?

0 Answers0