I ran into a problem that whenever a stream is played by my application in Android 4.0+, the OnPrepare method from MediaPlayer.OnPreparedListener is called before the stream loads and therefore I can not tell the user that the load / buffer stream is running. I already found a question of the same type, but did not answer. Here's what I'm doing.
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); playVideo(someRtspUrl); } private void playVideo(String url) { // if app is running on Google TV then change RTSP link to HLS if (url.contains("rtsp")) { // split the RTSP URL and make it as HLS String videoUrlParts[] = url.split("\\?"); url = videoUrlParts[0].replace("rtsp", "http") + "/playlist.m3u8"; if (videoUrlParts.length > 1) url += "?" + videoUrlParts[1]; } mVideoView.setVideoURI(Uri.parse(url)); mVideoView.requestFocus(); mVideoView.setOnCompletionListener(this); mVideoView.setOnPreparedListener(this); } @Override public void onPrepared(MediaPlayer player) { dismissProgressDialog(); mVideoView.start(); }
This code works great on Google TV and other Android 3.0+ and <4.0+
java android video-streaming media-player android-4.2-jelly-bean
Quamber ali
source share