String fileName = intent.getStringExtra(FILENAME);
File output = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MUSIC),
fileName);
然后我将文件的路径传递给MediaPlayer:
Uri uri = Uri.parse("file://"+Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MUSIC)+ "/"+title);
mpintro.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mpintro.setDataSource(getApplicationContext(), uri);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
但是它不起作用,我是否缺少某些东西,或者还有其他解决方法。我可能看到堆栈上的每个线程都在解决此问题,但是它们都不起作用。也许将mp3存储在sqlite DB中并使用ContentProvider毕竟不是一个坏主意吗?