I'm having a crack at using the MediaPlayer object and not having much success. If I add a sound asset to my raw folder and call it using the int value within R, it works fine. But I want to be able to pull things off of url.
According to all of the documentation I've read setDataSource() should accept a string param with a url to a file.
I keep getting an IO exception on the prepare() statement. I've even tried copying the file locally and still no dice.
Anyone have any ideas?
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();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…