i want get audio files in sd card

前端 未结 1 1267
孤城傲影
孤城傲影 2020-12-20 07:14

In my app I want to set the ringtone when I get an incoming call... How to open the SDCARD and get audio files and list it.. How to get th

相关标签:
1条回答
  • 2020-12-20 07:23

    MediaScanner finds music for you, populating the MediaStore database. Here's some code to look up a music entry:

    final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        final String[] cursor_cols = {
                MediaStore.Audio.Media._ID,
                MediaStore.Audio.Media.ARTIST,
                MediaStore.Audio.Media.ALBUM,
                MediaStore.Audio.Media.TITLE,
        };
        final String where = MediaStore.Audio.Media.IS_MUSIC + "=1";
        final Cursor cursor = getContentResolver().query(uri, cursor_cols, where, null, null);
        cursor.moveToNext();
        final String artist = cursor.getString(_cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
        final String album = cursor.getString(_cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
        final String track = cursor.getString(_cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
        doSomethingHere(artist, album, track);
    

    The "data" field contains a handle you can use with MediaPlayer. while doing this media files scanning and indexing for the first time, scan it using a AsyncTask, but later when a intent is received do it using a service.

    0 讨论(0)
提交回复
热议问题