I am trying to get to the bottom of an issue with MediaPlayer within and Android project, this issue is that the live stream stops after 22 minutes (exactly) consistently with the following displayed:
2021-09-15 19:00:59.600 com.projectname W/MediaHTTPConnection: readAt 20709376 / 32768 => java.net.ProtocolException
2021-09-15 19:00:59.600 com.projectname W/MediaHTTPConnection: readAt 20709209 / 32768 => java.net.ProtocolException
2021-08-30 19:45:30.559 com.projectname E/MediaPlayerNative: error (1, -1010)
2021-08-30 19:45:30.560 com.projectname E/MediaPlayerNative: error (1, -1010)
2021-08-30 19:45:30.560 com.projectname E/MediaPlayerNative: error (1, -1010)
2021-08-30 19:45:30.560 com.projectname E/MediaPlayer: Error (1,-1010)
2021-08-30 19:45:30.561 com.projectname E/MediaPlayer: Error (1,-1010)
I have discovered from this page http://androidxref.com/4.0.4/xref/frameworks/base/include/media/stagefright/MediaErrors.h#37 that -1010 means 'Unsupported Media' but the app plays the stream fine solidly for 22 minutes until the audio stream then stops and the log displays the above (the app does not crash, just the audio stops).
This is the code that starts the live stream playing:
@Override
public void setStreamSource(StreamSource streamSource) {
try {
if (!mediaPlayer.isPlaying()) {
mediaPlayer.setDataSource(streamSource.getAudioUrl());
// Prepare the media player
mediaPlayer.prepare();
// Start playing audio from http url
mediaPlayer.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
I have tried changing mediaPlayer.prepare(); to mediaPlayer.prepareAsync(); but the stream doesn't start then.
I'm not aware of anything within the app that happens at the 22 minute mark so my thoughts are going to something like the live stream running out of buffered audio and stops playing.
Has anyone seen anything similar and have an idea of what the problem could be?
Does anyone know how to specify a buffer size? (I'm not familiar).
I guess alternatively I could detect if the error happens and restart playback, but that doesn't sound like the best solution.
Thanks in advance for any assistance.