开发者

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

开发者 https://www.devze.com 2023-03-31 05:07 出处:网络
I am new to android. I am writing a small application that reads files from the SD card. It picks a song from theSD card and then plays that song as a 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

精彩评论

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

关注公众号