最近在做一个音乐播放器,现在遇到一个难题就是不知道怎么读取指定目录下的音乐文件,MediaStore.Audio.Media好像只能读取SD卡中所有的音乐文件,不能读到指定目录的音乐文件!知道的请留下神迹!

解决方案 »

  1.   

    很简单啊,还是用MediaStore.Audio.Media,通过循环判断音乐的路径是不是你指定的那个路径,是的话就列出来
      

  2.   

            ContentResolver mResolver = getContentResolver();   
            Cursor cursor = mResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
            
            int i = 0;
            int cursorCount = cursor.getCount();
            if (cursorCount >0 )
            {
             cursor.moveToFirst();
                while (i < cursorCount)
                {
                 //歌曲文件的路径 :MediaStore.Audio.Media.DATA 
                    url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
                    if(url.toLowerCase().indexOf("指定的歌曲路径") > 0)
                    {
                     ......
                    }            
                    i++;
                    cursor.moveToNext();                
                }
                cursor.close();
    }
      

  3.   

    File clickfile=new File("指定的路径");String [] checkfilepath=clickfile.getPath().split("\\.");if(checkfilepath.length>0&&clickfile.getPath().split("\\.")[1].equals("mp3"))
         {
         Intent it=new Intent();
             it.setAction(Intent.ACTION_VIEW);
             it.setDataAndType(Uri.parse("file:/"+clickfile.getPath()), "audio/mp3");
             Log.i(TAG, Uri.parse("file:/"+clickfile.getPath()).toString());
            
             startActivity(it);
         }
      

  4.   

    呵呵,真的谢谢各位,说真的,我刚才就在想这个,就在刚才我终于想出来了用的是3楼和4楼的方法,通过判断路径把所以在指定目录下的文件加入List,至于其它大神的方法我也想过,但是用这种那种JAVA遍历路径的方法获取音乐的一些信息就比较难了,所以我才会想用MediaStore.Audio.Media的那种方法,但是我一直找不到他的实现原理!