开发者

How can i know the url of sdcard for getting songs for ring tone?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜