PowenKo, Android File,Uri, resource, sd card, http

January 13, 2012   ·   0 Comments

To better explain how to obtain a file’s URI, let’s assume that we are trying to get the URI of a video named intro.3gp which is in the /res/raw folder. Here’s the code to get the URI:

  1. Uri introURI;
  2. introURI = Uri.parse(“android.resource://your.app.package/” + R.raw.intro);

Now let’s assume the same intro.3gp is at the root of the SD card. The code to correctly get the file’s URI would be:

  1. String introURI;
  2. introURI = Uri.parse(“file:///sdcard/intro.3gp”);

And that’s it! This method can also be used to obtain any file URI. Expanding a little bit the previous example, to correctly play the video file while using the emulator, instead of usingsetVideoPath(String path) like:

  1. String introURI = “file:///sdcard/intro.3gp”;
  2. VideoView videoView;
  3. //…Omitted videoView initialization…
  4. videoView.setVideoPath(path);

Obtain the video URI, as show on the previous examples and use the setVideoURI(URI uri)method, like this:

  1. Uri introURI,
  2. //obtain the URI of the video file from the ‘res’ folder
  3. introURI = Uri.parse(“android.resource://your.app.package/” + R.raw.intro);
  4. //or get it the URI from a the video file at the SD card
  5. //introURI = Uri.parse(“android.resource://your.app.package/” + R.raw.intro);
  6. VideoView videoView;
  7. //…Omitted videoView initialization…
  8. videoView.setURI(introURI);
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter


Readers Comments (0)

You must be logged in to post a comment.

PowenKo’s Online Store




Recent Posts