Android MediaPlayer.prepare throws status=0×1 error(1, -2147483648)
Question: I have a weird error message and can’t find solution. Project: Android with Eclipse IDE and Android SDK, min. API level 10, source code is attached. Problem: I can play none of my downloaded and saved media files from the application’s own data folder (/data/data/com.mypackage/myfile.mp4) by the MediaPlayer class. I double checked the video format. It can be even played when I place it into the /mnt/sdcard/… folder. Android shows a message saying “Cannot Play Video: Sorry, this video cannot be played”. In the log file I can find an error: MediaPlayer error(1, -2147483648) and Prepare failed. status=0×1. What’s the issue?
Answer: The typical errors are as follows:
1. File path is in error. Incorrect directory or Url or Uri found.
2. Media file is in error, incompatible format.
3. Missing permissions.
In Android MediaPlayer mp = new MediaPlayer(); does not create your apps’s own object. It uses “another” application and requires world-readable permissions for the application’s local media files. “World-readable” means another application can see it. You can view the permissions of these files on the DDMS window in Eclipse IDE:

File permission in data/data/yourapp/files folder
When your app is in error, you will probably see that “-rw——” gray line, which means that only your application has read/write permissions on your file(s).
For applications targetting SDK versions greater than Android 2.3, these permission flags can be explicitly set if desired. See File -> setReadable(,), or FileOutputStream documentation for hints:
Call openFileOutput() with the name of the file and the operating mode. This returns a FileOutputStream:
1 2 3 4 5 6 7 8 9 10 11 12 13 | // Sample: copy myfile.mp4 from 'assets' to internal /data/data/... folder FileOutputStream outputStream = context.openFileOutput("myfile.mp4", Context.MODE_WORLD_READABLE); InputStream inputStream = context.getAssets().open("myfile.mp4"); // Copy data byte[] buffer = new byte[8192]; int length; while ( (length=inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } // Close the streams inputStream.close(); outputStream.flush(); outputStream.close(); |
Comments
Log in to post (or reply to) a comment. You can use your Twitter account.
This blog was originally designed for our own project partners and freelance programmers to share questions and solutions in this online private pub. From April 1, 2011 we open the blog for all of you to add comments or ask a question in a new post. All comments and posts are moderated before they are posted to verify the quality of content on our pages. Comments are usually posted within 15 minutes. Posts may be re-edited. You can post source codes in comments using [code][/code] tag.



2
3
4
5
6
File file = context.getFileStreamPath(FileName);
if (file.exists()) {
// Set to Readable and MODE_WORLD_READABLE
file.setReadable(true, false);
}