I have an audio file in my assets directory. assets/audio/dance.mp3.
If I run context.getAssets().list("audio"); it shows up.
But when I try to use MediaPlayer.create(context,uri) it always fails and returns null.
none of this seems to work
private void tryLoad(String path,Context context)
{
Uri uri = Uri.parse(path);
this.audioPlayer = MediaPlayer.create(context,uri);
if (this.audioPlayer == null)
{
Log.d(TAG, "loadAudio: audioPlayer is null. current assets"+ uri.toString()) ;
}
else
{
Log.d(TAG, "loadAudio: WORKED"+ uri.toString()) ;
}
}
public void loadAudio(Context context)
{
if (this.audioPlayer != null)
return;
if (this.audioFile != null && this.audioFile.length() >0)
{
try
{
tryLoad("/dance.mp3",context);
tryLoad("dance.mp3",context);
tryLoad("audio/dance.mp3",context);
tryLoad("/audio/dance.mp3",context);
tryLoad("assets/audio/dance.mp3",context);
tryLoad("/assets/audio/dance.mp3",context);
tryLoad("\\dance.mp3",context);
tryLoad("dance.mp3",context);
tryLoad("audio\\dance.mp3",context);
tryLoad("\\audio\\dance.mp3",context);
tryLoad("assets\\audio\\dance.mp3",context);
tryLoad("\\assets\\audio\\dance.mp3",context);
}
catch (Exception e)
{
Log.d(TAG, "loadAudio exception: " + e.getMessage());
}
}
}