获取歌曲的路径从SD卡中的机器人 [英] Get path of song from SD card in android

查看:100
本文介绍了获取歌曲的路径从SD卡中的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我想获取从SD卡的歌,但我没能获得特定file.I的路径是用Android的API级别7不支持下面的方法。

In my android application I want to fetch song from SD card but I am not able to get the path of that particular file.I am using android api level 7 which doesn't support following method.

Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_MUSIC);

我也曾尝试以下code:

I have also tried following code :

path = Environment.getExternalStorageDirectory();

但我不知道如何指定的音乐道路file.Please提出一些solution.Thanx。

but I don't know how to specify path of music file.Please suggest some solution.Thanx.

推荐答案

获取从SD卡路径和歌曲名称。您可以从MediaStore歌曲的路径。

Get path and song Name from SD Card. You can find the path of the song from MediaStore.

媒体提供者包含的元数据可用于所有媒体内部和外部存储设备上。

The Media provider contains meta data for all available media on both internal and external storage devices.

private String[] STAR = { "*" };

public void ListAllSongs() 
    { 
        Cursor cursor;
        Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

        if (isSdPresent()) {
            cursor = getContentResolver().query(allsongsuri, STAR, selection, null, null);

            if (cursor != null) {
                if (cursor.moveToFirst()) {
                    do {
                        String songname = cursor
                                .getString(cursor
                                        .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
                        int song_id = cursor.getInt(cursor
                                .getColumnIndex(MediaStore.Audio.Media._ID));

                        String fullpath = cursor.getString(cursor
                                .getColumnIndex(MediaStore.Audio.Media.DATA));

                        String albumname = cursor.getString(cursor
                                .getColumnIndex(MediaStore.Audio.Media.ALBUM));

                    } while (cursor.moveToNext());
                }
                cursor.close();
            }
        }
    }


public static boolean isSdPresent() 
{
    return android.os.Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_MOUNTED);
}

这篇关于获取歌曲的路径从SD卡中的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆