So I have an IP camera that outputs a video stream I can connect to via the rtsp protocol. I want to display this in my android application, so I've set up a videoview using the following code;
VideoView vv = (VideoView)this.findViewById(R.id.videoView);
Uri uri = Uri.parse("rtsp://username:[email protected]:554/1/stream3");
vv.setVideoURI(uri);
vv.requestFocus();
vv.start();
I'm putting this in the onCreate() of the main activity class, so when the app loads up it automatically connects and starts streaming. My experience with this is that it works - but eventually gets choppy and or just stops randomnly and doesn't seem to ever get back to running again. I have to close the app and clear it from memory and restart it to get it back - but then it loses connection shortly after, meaning its pretty much useless.
I also found it seemed to lag a bit when touching on the screen objects like menus or buttons but that might just be a coincidence - I can't say for sure.
The thing is the stream is perfect from a PC on the same network via VLC using the same URL. So what am I doing wrong, and is there any better method of handling streaming video? I ultimately wanted to mate the videoview with some overlaid text and buttons, and potentially take screenshots when necessary. At the moment I'm lucky if I get video for a few seconds before it cuts out...
Some additional comments;
I've had some success running it for a longer frame of time - so it's not always bad which makes things difficult to diagnose. But when it stops it stops. Does videoview actively try to reconnect if it has lost a connection? Is there a way of demonstrating this with a progress indicator perhaps - so it doesn't look like it's doing nothing?