I am trying to make a mediaplayer in android streaming songs from Amazon S3.
I made the songs in my bucket public and it works fine when I stream them with the bowser.
But when it come to android, it throws me an exception like that.
11-20 01:28:37.720: W/System.err(736): java.io.FileNotFoundException: /https:/s3.amazonaws.com/soul-media/mp3s/1234.mp3: open failed: ENOENT (No such file or directory)
here is my code for the player
MediaPlayer mid= new MediaPlayer();
try {
FileInputStream fid= new FileInputStream("https://s3.amazonaws.com/soul-media/mp3s/1234.mp3");
mid.setDataSource(fid.getFD());
mid.prepare();
mid.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
It worked with android 4.1 but did not work with 2.2, can that be the issue?
I also tried some urls other than Amazon S3, it works. So is that something with Amazon?
Is there any reason you can’t just skip creating the
FileInputStreamand callmid.setDataSource("https://s3.amazonaws.com/...")via this overload? Does that work?Edit:
Apparently, instead of calling
preparefor streams, you should be callingprepareAsyncwhich should return immediately, like so:Does that help?