Uri of files in assets
I am using the RingtoneManager
to play sounds. Everything
works ok when I store sound files (.mp3) in the appropriate SD directories.
I find out the URI of the file and I give it to RingtoneManager
to play.
sd_uri = Uri.parse( "/sdcard/media/path/to/file" );
Ringtone rt = RingtoneManager.getRingtone( getApplicationContext(), sd_uri );
rt.play();
Just wondering what to do in case of tablets that do not come with an SD card.
My idea is to store sound files in res/开发者_如何转开发raw
or res/assets
dirs, but unlike MediaPlayer
that accepts resource identifiers, RingtoneManager
only wants Uri.
How do I get the Uri of files in res/raw
or res/assets
dir?
Ideally I would use res/raw
, to get R.raw.*
identifier, which might be handy.
Do not hardcode path as /sdcard
use Environment.getExternalStorageDirectory()
instead. This will remove the dependency on sdcard.
In my application I'm referencing to application res/asset located media file using URI like:
private static final String PLACEHOLDER="file:///android_asset/sample_video.3gp";
精彩评论