Pregunta

I am trying to play a video (target api 7) and I get the error (1, -18) and it says "Cannot Play Video". I could not find anyone else with this error.

I am trying to make a view appear in the current layout that plays the video.

The error means "Error due to general data processing".

My video file is a .mp4 file. I exported it using H264 in premiere pro using the option for "android phone and tablet".

I've watched many tutorials and none of their codes work for me. Example 1: http://www.sherif.mobi/2012/06/how-to-play-video-from-resources.html Example 2: http://www.helloandroid.com/tutorials/how-play-video-and-audio-android

My phone uses the 2.2.1 version (my app targets API 7) and I believe that might be the problem. On the simulator (which is extremely slow so I don't fully rely on it), I see the first image of the video so I know it can at least get to it.

Thanks!

¿Fue útil?

Solución

I have found out the problem. Turns out, even tho I exported the video "for android phone and tablet" it was still not the right format of .MP4. If you are having a video problem, try this code and make sure you try various formats of .mp4. It worked for me for api 7 and up.

 videoHolder = new VideoView(this);
 Uri video = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.test2);

videoHolder.setVideoURI(video);
videoHolder.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
//action to do when video is done
}
});
videoHolder.start();

Otros consejos

Take care of the support media type and resolution of your device. Error with mediaPlayer often, appear when your video media type, codecs, or resolution is not supported by your device.

Checkout the media type supported by Android in the documentation :

https://developer.android.com/guide/appendix/media-formats.html

For example, we can notice that device above 3.0 support .mp4, but not all of them support HD 720p.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top