I am new to android. I am writing a small application that reads files from the SD card. It picks a song from the SD card and then plays that song as a ring tone.
This is the code that plays the song:
MediaPlayer mp=MediaPlayer.create(Alarm.this, R.raw.airt开发者_开发问答el_new);
mp.start();
Instead of "R.raw.airtel_new" I would like to use the URI or the URL of a particular song that I have selected from the SD card.
Could any one help me?
The root directory of your SDCard (where it is mounted) is known by Environment.getExternalStorageDirectory().getAbsolutePath().
So this allows you picking the file /music/yourfile.ext on the SD:
final String rootDir  = Environment.getExternalStorageDirectory().getAbsolutePath();
final String yourFile = rootDir + "/music/yourfile.ext";
final MediaPlayer mp = MediaPlayer.create(Alarm.this, "file://" + yourfile);
More details on this method are available here.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论