I\'ve been really banging my head against the table trying to get the MediaPlayer class to try to play h.264-encoded videos on Android 2.1. My code is rather simple:
<If you are dealing with remote URL, use below code to get encoded url compatible with MediaPlayer.
public String getEncodedURL(String urlStr) throws Exception
{
URL url = new URL(urlStr);
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
urlStr = uri.toASCIIString();
return urlStr;
}
I had a similar problem. I had a zip file which contained sound files which were compressed. In order to pass them on to MediaPlayer
they needed to be uncompressed. When I placed them inside application's cache directory (context.getCacheDir()
), MediaPlayer
returned the same error which you described.
But when I placed them on external storage (Environment.getExternalStorageDirectory()
), everything started working.
This is my solution:
MediaPlayer mediaPlayer = new MediaPlayer();
FileInputStream fis = null;
try {
File directory = new File("android.resource://com.example.myapp/raw/");
fis = new FileInputStream(directory);
mediaPlayer.setDataSource(fis.getFD());
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepare();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ignore) {
}
}
}
playing mp3 files instead of wmva fixed it. Apparently that isn't an issue on API 19
On my opinion i will ask you to check back your location of your media files<< SONG PATH or MOVIE PATH >>. I faced with this exception, i have overcome by correct "SONG PATH"
In my case it was just a filename that it didn't like:
/storage/emulated/0/appname/2018-03-12T11:52:08Z.wav
Removed the hyphens and colons, and the exception went away.