我的问题是我的代码无法正常工作。我的资产/专题歌文件夹中有100多个mp3商店。
flAnthem = c.getString(c.getColumnIndex(KEY_ANTHEM));
flAnthemSDCard = c.getString(c.getColumnIndex(KEY_ANTHEM_SDCARD));
AssetManager assetManager= getAssets();
InputStream inputStream = null;
try{
inputStream = assetManager.open("anthem/" + flAnthem);
mediaPlayer.setDataSource(String.valueOf(inputStream));
mediaPlayer.prepare();
mediaPlayer.start();
}catch(IOException e){
e.printStackTrace();
}
答案 0 :(得分:1)
替换
inputStream = assetManager.open("anthem/" + flAnthem); mediaPlayer.setDataSource(String.valueOf(inputStream)); //DataSource is not correctly setted.
使用AssetFileDescriptor
flAnthem = c.getString(c.getColumnIndex(KEY_ANTHEM)) + ".mp3"; // don't forget extension
AssetFileDescriptor descriptor = getAssets().openFd("anthem/"+mediaName);
mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
顺便说一句