Android MediaStore查询找不到任何m4a音频文件。
创始人
2024-09-30 12:30:17
0

要解决Android MediaStore查询找不到任何m4a音频文件的问题,可以使用以下代码示例:

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

public class AudioHelper {
    private static final String TAG = "AudioHelper";
    
    public static void queryM4aFiles(Context context) {
        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

        String[] projection = {
                MediaStore.Audio.Media._ID,
                MediaStore.Audio.Media.TITLE,
                MediaStore.Audio.Media.DATA
        };

        String selection = MediaStore.Audio.Media.DATA + " LIKE ?";
        String[] selectionArgs = new String[]{"%.m4a"};

        Cursor cursor = null;
        try {
            cursor = contentResolver.query(uri, projection, selection, selectionArgs, null);
            if (cursor != null && cursor.moveToFirst()) {
                do {
                    long id = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
                    String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
                    String data = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));

                    Log.d(TAG, "ID: " + id + ", Title: " + title + ", Data: " + data);
                } while (cursor.moveToNext());
            } else {
                Log.d(TAG, "No m4a audio files found.");
            }
        } catch (Exception e) {
            Log.e(TAG, "Error querying m4a audio files: " + e.getMessage());
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
}

然后,在你的Activity或Fragment中调用queryM4aFiles方法来查询m4a音频文件:

AudioHelper.queryM4aFiles(getApplicationContext());

这将打印出所有找到的m4a音频文件的ID、标题和路径。如果没有找到任何m4a音频文件,将输出"No m4a audio files found."

相关内容

热门资讯

查到实测!wejoker透视方... 查到实测!wejoker透视方法,hhpoker辅助软件是真的么,AI教程(有挂透视);1.hhpo...
透视工具!we-poker辅助... 透视工具!we-poker辅助软件教程(透视)一直真的有挂(详细辅助曝光教程)辅助器中分为三种模型:...
玩家必备教程!wepoker透... 玩家必备教程!wepoker透视脚本免费app,we-poker软件,攻略教程(有挂方法)1、玩家可...
透视ai代打!werplan透... 透视ai代打!werplan透视挂(透视)好像存在有挂(详细辅助揭秘教程)1、在ai机器人技巧中,中...
分享认知!wepoker的辅助... 分享认知!wepoker的辅助器,来玩app 德州 辅助,切实教程(有挂方法)是由北京得来玩app ...
透视免费!wepoker作弊视... 透视免费!wepoker作弊视频(透视)确实有挂(详细辅助微扑克教程)1、透视辅助简单,软件透明挂操...
实操分享!wepoker新号好... 实操分享!wepoker新号好一点吗,wepokerplus脚本,2025新版教程(有挂教程)关于w...
透视总结!wepoker黑侠辅... 透视总结!wepoker黑侠辅助器正版下载(透视)一贯有挂(详细辅助解密教程)1、进入游戏-大厅左侧...
推荐十款!hhpoker透视方... 1、推荐十款!hhpoker透视方法,wepoker究竟有没有透视,2025新版(有挂辅助);详细教...
透视透视!hhpoker智能辅... 透视透视!hhpoker智能辅助插件(透视)切实有挂(详细辅助必胜教程)1、起透看视 透明视辅助2、...