1

So I created a directory on the internal storage like so:

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

Then I download files from a server and save them inside the directory like this:

URL url = new URL(urlString);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream is = url.openStream();
Log.d("DOWNLOAD NAME",name);
FileOutputStream fos = new FileOutputStream(mediadir+name);
etc

Then files are saved successfully, then next I want to play them like this:

String path = filelist[playListIndex].getAbsolutePath();
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVisibility(View.VISIBLE);
videoView.setOnCompletionListener(this);
videoView.setVideoPath(path);
videoView.start();

where path is :

/data/data/com.mypackage/tvr/video.mp4

The file does not want to play with this error:

02-20 15:57:21.447: E/MediaPlayer(24143): error (1, -2147483648)

And on the device a message pops up : Cannot play video, Sorry this video cannot be player.

Is this a issue with rights or what? If it is, I was thinking because I created them, I have the rights to them?

Harry
  • 13,091
  • 29
  • 107
  • 167

2 Answers2

0

CommonsWare has a good example on how to use the VideoView. Here is a link to someone who had a similar issue with video not wanting to play: Playing a video in VideoView in Android

Also here is a video class of his example that I found useful when learning how to incorporate the VideoView: https://github.com/commonsguy/cw-advandroid/blob/master/Media/Video/src/com/commonsware/android/video/VideoDemo.java hope this helps.

I would also make sure that you have the permission settings in your manifest set:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Community
  • 1
  • 1
cking24343
  • 3,173
  • 1
  • 21
  • 23
  • Thansk, I will have a look at those links. I do have that permission set in the manifest – Harry Feb 20 '13 at 14:57
  • Could be related to the video file that you are trying to access, have you tried a different video? do you still get the same error? try using this one: [link](http://www.law.duke.edu/cspd/contest/finalists/viewentry.php?file=docandyou) – cking24343 Feb 20 '13 at 15:30
  • the video works fine. I tetsted it by playing it from the raw resource and it works. So thats not the problem – Harry Feb 20 '13 at 15:41
  • that may be, that the video plays when accessing it directly. Did you try the other video file, just to see if that too gives you the same error? – cking24343 Feb 20 '13 at 19:23
  • Not sure that I am getting what your are saying.. I mean when playing the video from the phones res.raw.video1 it works. – Harry Feb 21 '13 at 06:27
  • Just saying you should try another video file other than the one that you have. Was just curious if you have the same issue with a different file when trying to view it with the VideoView controller. – cking24343 Feb 21 '13 at 14:42
0

The problem might be with the video encoding. Android FROYO and Gingerbread doesn't support H264 formats other than "Baseline" H264. So if your video is Mp4 & H264 encoded make sure its "AVC baseline" encoded. Use some tools like "Media info" in windows/Linux and check your video encoding. Convert the video to Baseline if possible.

An alternative workaround is to skip the Videoview and use a video play intent and redirect the playback to an app. User will be prompted to pick a player to handle the playback. Obviously if the video view cant play the file, the default player also wont be able to handle the file. you can choose some other installed player like Mx-Player which will stream the file perfectly.

Ajith M A
  • 3,838
  • 3
  • 32
  • 55