Am trying to play a video stored in the internal storage in Android. However, no matter what I do it keeps coming back with either a -1 error or a -38 error. Both seem to be rather generic errors hence are not much intelligible.
I am wondering if it is possible to use a VideoView and not a MediaPlayer instance to play a video file from the local storage.
The steps involved in my app include,
Storing the file in internal storage (note i use the convention for ensuring that it has global read permissions. i.e
openFileOutput(file_name, Context.MODE_WORLD_READABLE);
Reading the media file back at a later point from this location, and playing it in a videoView.
String filePath = "file://" + getFilesDir()+File.separator+file_name;
Uri videoUri = Uri.parse(filePath);
Log.d("Video Player", filePath);
videoPlayer.setVideoURI(videoUri);
I also went through other links in StackOverflow which point out that I need to implement a CustomContentProvider to be able to read these files. Is there a direct way of accessing the file uri and setting it to the videoView without having to resorting to creating a custom content provider and using a mediaPlayer instead of a videoView.
Other StackOverflow references used
please try this. I have explained the procedure to play video from raw folder on this link: Video player not workig! . On that, if you modify
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.VideoName);
with
Uri uri = Uri.parse(Environment.getExternalStorageDirectory()+"<path to your video>");
For example:
Uri uri = Uri.parse(Environment.getExternalStorageDirectory()+"/dcim/camera/2012-05-15_17-50-39_319.3gp");
I think will solve your issue. Remember to give the necessary permissions on the manifest.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With