I am trying to develop a hls player on android devices, and i have some test-streams i can play with. A problem i have is that the HLS stream just "stops", freezes at some random locations, it could be after 1 minute, or after 20. The error i get is:
11-20 14:14:10.484: W/AudioSystem(18531): AudioFlinger server died! 11-20 14:14:10.484: W/IMediaDeathNotifier(18531): media server died
and 11-20 14:14:10.484: E/MediaPlayer(18531): Error (100,0)
I've got basically no idea on how to prevent or restart the stream if this is happening. I don't even know why it happens. So if someone could answer that question, i would be very happy :).
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
mMediaPlayer.reset();
return false;
}
});
mMediaPlayer.setDataSource(path);
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepareAsync();
//mMediaPlayer.prepare();
if(extras.getString("type") == "VOD") {
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
}
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setScreenOnWhilePlaying(true);
//mMediaPlayer.setOnVideoSizeChangedListener(this);
//mcontroller = new MediaController(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
public void onPrepared(MediaPlayer mediaplayer) {
Log.d(TAG, "onPrepared called");
mIsVideoReadyToBePlayed = true;
if (mIsVideoReadyToBePlayed) {
runOnUiThread(new Runnable() {
public void run() {
startVideoPlayback();
}
});
}
mcontroller = new MediaController(this);
mcontroller.setMediaPlayer(this);
mcontroller.setAnchorView(findViewById(R.id.surface));
mcontroller.setEnabled(true);
handler.post(new Runnable() {
public void run() {
mcontroller.setEnabled(true);
mcontroller.show();
}
});
}
Please tell if you need more code.
I think it's just what it says: network issues have made the MediaPlayer
think the server closed the connection.
For HTTP streaming, I would suggest sticking a simple proxy server on the device so that you have a bit more control over the data that gets sent to the player. The Apache libraries are pretty easy to use by themselves, or you can pick up a lightweight wrapper like Naga. You can make reconnect requests at the exact byte you left off in case of errors like this. There are other benefits, like being able to cache data if so desired, but being in control of the remote communication provides a level of freedom you won't otherwise find with the MediaPlayer
.
Note for future reference: this answer wasn't good for HLS. See the comments.
Check your error listener for Error(100,0). Release the player don't just reset it and recreate another object.
One reason is multi-threaded access to the MediaPlayer service which uses the AudioService. Another -which is probably your case- is memory issues. try to minimize number of players running together and pay close attention to how much memory your app is using.
Here is how to detect Error(100,0):
mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
mMediaPlayer.release();
//create another mediaplayer preferrably in another thread
return false;
}
});
来源:https://stackoverflow.com/questions/20097512/android-audioflinger-server-died-media-server-died