I need to play audio file from remote server in my app. I could play when I tested with localhost server (using WAMP). When the same file supplied from the server it is not
The answer provided above provides synchronous fetching and playing, meaning currently executing thread will be blocked until prepare() is completed.
prepareAsync() can be used instead to "prepare" the stream asynchronously. You also will need to handle onPrepared() event to start playing.
mediaPlayer.setDataSource(URL here);
mediaPlayer.prepareAsync();
Add OnPrepared event handler:
mPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mPlayer.start();
}
});
Still, apparently there is no way to configure streaming buffer size. Frustrating...