'Can't play cached audio file Android java
I want to download, cache and play an audio file from the network. I managed to download and save it to the context.getCacheDir(). Absolute path is "/data/user/0/org.kimp.mustep/cache/floor_01/entrance_ru.mp3".
When I try to play it with a MediaPlayer's object the app crashes.
There is some ways I tried to do that:
MediaPlayer player = new MediaPlayer();
FileInputStream inputStream = new FileInputStream(target);
player.setDataSource(inputStream.getFD());
inputStream.close();
player.setAudioAttributes(new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build());
player.prepare();
player.start();
and
MediaPlayer player = new MediaPlayer();
player.setDataSource(activity.getBaseContext(), Uri.fromFile(target));
player.prepare();
player.start();
target is a File object with the mp3
And every time I have an error:
error (1, -2147483648)
java.io.IOException: Prepare failed.: status=0x1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
