我想制作一个可以向我提供SDCard中可用音频文件列表的应用程序,然后我应该能够从我的应用程序中播放该音频文件。甚至暂停恢复音频播放等功能。
有什么帮助吗?
最佳答案
您可以看到以下代码,用于从URL流音频
private void playVideo() {
try {
final String path = "http://www.a1freesoundeffects.com/animals12557/catmeow.wav";
// If the path has not changed, just start the media player
if (path.equals(current) && mp != null) {
mp.start();
return;
}
current = path;
// Create a new media player and set the listeners
mp = new MediaPlayer();
mp.setDataSource(path);
mp.prepare();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
if (mp != null) {
mp.stop();
mp.release();
}
}
}