如何从内部存储中获取没有SD卡插槽的电话

时间:2018-06-08 10:17:19

标签: java android android-mediaplayer

我拥有一部没有任何SD卡插槽的手机,但它有64GB的内部存储空间。问题是每当我使用我的自定义媒体播放器加载歌曲时,它只加载.ogg个文件(根本没有MP3文件),这发生在uri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;时。但是当uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;崩溃应用程序时,因为没有要搜索的SD卡槽。

这是我的代码,

    private void loadSongs() {
    Uri uri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
    //Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

    String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
    Cursor cursor = getContentResolver().query(uri, null, selection, null, null);
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
                String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
                String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));

                Log.i("DATA111", url);

                mediaMetadataRetrieve = new MediaMetadataRetriever();
                mediaMetadataRetrieve.setDataSource(url);

                art = mediaMetadataRetrieve.getEmbeddedPicture();

                if (art != null) {
                    songImage = BitmapFactory.decodeByteArray(art, 0, art.length);
                }

                SongInfo s = new SongInfo(name, artist, url, songImage);
                _songs.add(s);

            } while (cursor.moveToNext());
        }

        cursor.close();
        songAdapter = new SongAdapter(MainActivity.this, _songs);

    }
}

有人能找到我解决这个问题的方法吗?

Logcats结果:

I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps][DM]/01 - ZNMD - Dil Dhadakne Do [www.DJMaza.Com].mp3
 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps][DM]/02 - ZNMD - Ik Junoon (Paint It Red) [www.DJMaza.Com].mp3
 /storage/emulated/0/DraStic/shaders/fxaa/fxaa.dsda:103)

运行结果:

                   Caused by: java.lang.RuntimeException: setDataSource failed: status = 0x80000000
                  at android.media.MediaMetadataRetriever.setDataSource(Native Method)
                  at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:69)
                  at com.example.captain.mp2x.MainActivity.loadSongs(MainActivity.java:184)
                  at com.example.captain.mp2x.MainActivity.checkUserPermission(MainActivity.java:146)
                  at com.example.captain.mp2x.MainActivity.onCreate(MainActivity.java:103)

这是Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

时记录的内容

I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/01 - ZNMD - Dil Dhadakne Do [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/02 - ZNMD - Ik Junoon (Paint It Red) [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/03 - ZNMD - Khaabon Ke Parinday [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/04 - ZNMD - Senorita [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/05 - ZNMD - Der Lagi Lekin [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/06 - ZNMD - Sooraj Ki Baahon Mein [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/07 - ZNMD - Toh Zinda Ho Tum [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/08 - ZNMD - Ik Junoon (Remix) [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/Zindagi Na Milegi Dobara [2011-MP3-VBR-320Kbps] - [DM]/09 - ZNMD - Senorita (Remix) [www.DJMaza.Com].mp3 I/DATA111: /storage/emulated/0/Download/Saints Row The Third Theme Ringtone.m4a E/MediaMetadataRetrieverJNI: getEmbeddedPicture: Call to getEmbeddedPicture failed. I/DATA111: /storage/emulated/0/MIUI/ringtone/Saints Row The Third Theme Ringtone.m4a E/MediaMetadataRetrieverJNI: getEmbeddedPicture: Call to getEmbeddedPicture failed. I/DATA111: /storage/emulated/0/DraStic/shaders/fxaa/fxaa.dsd

当它是Uri uri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;时,它会显示I/DATA111: /system/media/audio/ui/Effect_Tick.ogg E/MediaMetadataRetrieverJNI: getEmbeddedPicture: Call to getEmbeddedPicture failed.和许多其他.ogg文件。

1 个答案:

答案 0 :(得分:0)

检查您是否获得了有效的网址。

检查文件是否存在以及是否跳过。