我在使用 MediaPlayer 对象时遇到了困难,但没有取得太大的成功。如果我将声音资产添加到我的原始文件夹并使用 R 中的 int 值调用它,它工作正常。但我希望能够从 url 中提取内容。
根据我读过的所有文档, setDataSource() 应该接受带有文件 url 的字符串参数。
我在 prepare() 语句中不断收到 IO 异常。我什至尝试在本地复制文件,但仍然没有骰子。
有人有想法么?
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("http://www.urltofile.com/file.mp3");
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}