Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between VideoView's setVideoPath and setVideoURI

Tags:

java

android

VideoView has two different ways of specifying which video to play:

  • setVideoPath(String path)
  • setVideoUri(Uri uri)

What is the difference between the two and when should one or the other be used?

like image 772
Henrik Karlsson Avatar asked May 24 '15 21:05

Henrik Karlsson


1 Answers

Look at the source code, nothing is different apart from the type you pass.

/**
 * Sets video path.
 *
 * @param path the path of the video.
 */
public void setVideoPath(String path) {
    setVideoURI(Uri.parse(path));
}
/**
 * Sets video URI.
 *
 * @param uri the URI of the video.
 */
public void setVideoURI(Uri uri) {
    setVideoURI(uri, null);
}

If you use setVideoPath it creates the Uri for you, so use whichever you want - depending on if you have a Uri or String path.

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/VideoView.java

like image 102
Blundell Avatar answered Sep 28 '22 04:09

Blundell