Currently, when using video applications, the more advanced technology is RTSP Streaming Media. What if we use the android playback control videoview to play the RTSP stream?
RTSP Streaming Media Link:
Http: // 218.204.223.237: 8081/WAP/
This link contains all RTSP Streaming Media Links. Now we will use videoview to play the RTSP stream in it. Let's test it with a link:
RTSP: // 218.204.223.237: 554/live/1/66251fc11108191f/e7ooqwcfbqjoo80j. SDP.
Effect:
The core code is as follows:
Java code
- Package com. Video. RTSP;
- Import Android. App. activity;
- Import android.net. Uri;
- Import Android. OS. Bundle;
- Import Android. View. view;
- Import Android. widget. Button;
- Import Android. widget. edittext;
- Import Android. widget. videoview;
- Public class rtspactivity extends activity {
- /** Called when the activity is first created .*/
- Button playbutton;
- Videoview;
- Edittext rtspurl;
- @ Override
- Public void oncreate (bundle savedinstancestate ){
- Super. oncreate (savedinstancestate );
- Setcontentview (R. layout. Main );
- Rtspurl = (edittext) This. findviewbyid (R. Id. url );
- Playbutton = (button) This. findviewbyid (R. Id. start_play );
- Playbutton. setonclicklistener (New button. onclicklistener (){
- Public void onclick (view v ){
- Playrtspstream (rtspurl. geteditabletext (). tostring ());
- }
- });
- Videoview = (videoview) This. findviewbyid (R. Id. rtsp_player );
- }
- // Play RTSP stream
- Private void playrtspstream (string rtspurl ){
- Videoview. setvideouri (URI. parse (rtspurl ));
- Videoview. requestfocus ();
- Videoview. Start ();
- }
- }
After you click to start playing the video, it generally takes a few seconds to start playing the video. You can directly set the RTSP address to be played: setvideouri (RTSP address)