There is a significant lag (5-10 seconds) between when I try to start a video stream and when the stream starts to be displayed. In trying to debug this, I thought I'd output a message when the state changes to Started (from this diagram http://developer.android.com/reference/android/media/MediaPlayer.html). However, there does not seem to be a callback that is triggered at this point. Does anyone know how to detect when the MediaPlayer starts?
Asked
Active
Viewed 1,197 times
2
-
The amount of time it takes for a video stream to show on the screen depends on a lot of factors, including but not limited to the type of stream, the behavior of the media server, and the current network connection. Out of curiosity, are you just referring to the call to `start`, or are you including calls to `prepare` or `prepareAsync`? To be honest, you should probably be looking at the requests and responses sent over the network instead of the `MediaPlayer`. – Dave Sep 28 '13 at 12:33
-
@Dave I call prepareAsync, then from onPrepared I call start(). But after I call start, there is still a significant delay until the video starts. The "video actually starts" is the event I am looking for. I don't suppose there is an API to look at the network responses you're talking about? – David Doria Sep 30 '13 at 11:42
-
There's no API from Android unless you're willing to build a proxy server to put in between the MediaPlayer and the real server ([it's not that hard](http://stackoverflow.com/questions/12701249/getting-access-to-media-player-cache/18627606#18627606)). If you have a rooted device, you can put a packet sniffer on it like [Shark for Root](https://play.google.com/store/apps/details?id=lv.n3o.shark&hl=en) (it's Wireshark for Android). Or you can use a server that you have control over to serve media. – Dave Sep 30 '13 at 13:16
1 Answers
0
so this might be a little late ;-)
i solved this by adding the onMediaTimeDiscontinuityListener. it will set the mediaClockRate to 1.0 at the exact moment the media is playing.
mediaPlayer.setOnMediaTimeDiscontinuityListener { mp, mts ->
if (mts.mediaClockRate == 1.0f) {
// media is started !!! do your thing here...
}
}
maybe it helps other people :) i still use the old player because it plays my byte-array very easily, i tried to use the new media3 exoplayer but now i like my fix better :)

Veit
- 101
- 1
- 5