4

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();
Harry
  • 13,091
  • 29
  • 107
  • 167

1 Answers1

6

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

Community
  • 1
  • 1
pete
  • 313
  • 2
  • 10
  • @Harry, is my answer not clear enough to be accepted? If it is, please do so as I need the karma points! :) – pete May 16 '16 at 13:50