在 MediaPlayer.create 方法中可以使用原始文件的 id,但如何在 setDataSource 方法中使用它?
最佳答案
AssetFileDescriptor afd = context.getResources().openRawResourceFd(resid);
if (afd == null) return;
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
您可能希望将 try-catch 添加到 block 中。
关于android - 在 MediaPlayer 中将数据源设置为原始 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1283499/