Use prepareAsync() and setOnPreparedListener() instead of prepare() . prepare() blocks the UI thread until it returns and is not recommended for the thread. This may be the cause of your failure.
mp = new MediaPlayer(); try { mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.setDataSource(res); mp.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer player) { mp.start(); } }); mp.prepareAsync(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { }
http://developer.android.com/reference/android/media/MediaPlayer.html#prepare ()
Play the player for synchronous playback. After setting the data source and display surface, you need to either call prepare () or prepareAsync (). For files, it's ok to call prepare (), which blocks until MediaPlayer is ready to play.
Otherwise, I think this is your bottleneck. The fastest way to speed things up is to provide fast data exchange between the server and the client. It seems that your code is not so bad.
source share