VideoView vs MediaPlayer?

Harry picture Harry · Feb 21, 2013 · Viewed 7.7k times · Source

Please tell me why this would work on with MediaPLayer and not in videoView? And how to make it work with a video view?

Videos are downloaded form an API and saved in this folder I created:

File mediadir = cw.getDir("tvr", Context.MODE_PRIVATE);

VideoView

final Uri uri = Uri.parse(path);
// path = /data/data/com.foo.app/tvr/video.mp4
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVisibility(View.VISIBLE);
videoView.setOnCompletionListener(this);
videoView.setVideoURI(Uri.parse(path));
videoView.start();

Error VideoView Sorry, this Video cannot be player and error (1, -2...)

MediaPlayer --- THIS WORKS

FileInputStream fileInputStream = new FileInputStream(path);

 MediaPlayer pl = new MediaPlayer();
 pl.setDataSource(fileInputStream.getFD());
 pl.prepare();
 pl.start();

Answer

pete picture pete · Jul 11, 2013

The basic reason is the MODE_PRIVATE, which disallow VideoView and MediaPlayer from playing non-World Readable files, unless you pass the FD as you have.

Here's a more detailed explanation