How does Android videoview play RTSP streams?

Source: Internet
Author: User

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

  1. Package com. Video. RTSP;
  2. Import Android. App. activity;
  3. Import android.net. Uri;
  4. Import Android. OS. Bundle;
  5. Import Android. View. view;
  6. Import Android. widget. Button;
  7. Import Android. widget. edittext;
  8. Import Android. widget. videoview;
  9. Public class rtspactivity extends activity {
  10. /** Called when the activity is first created .*/
  11. Button playbutton;
  12. Videoview;
  13. Edittext rtspurl;
  14. @ Override
  15. Public void oncreate (bundle savedinstancestate ){
  16. Super. oncreate (savedinstancestate );
  17. Setcontentview (R. layout. Main );
  18. Rtspurl = (edittext) This. findviewbyid (R. Id. url );
  19. Playbutton = (button) This. findviewbyid (R. Id. start_play );
  20. Playbutton. setonclicklistener (New button. onclicklistener (){
  21. Public void onclick (view v ){
  22. Playrtspstream (rtspurl. geteditabletext (). tostring ());
  23. }
  24. });
  25. Videoview = (videoview) This. findviewbyid (R. Id. rtsp_player );
  26. }
  27. // Play RTSP stream
  28. Private void playrtspstream (string rtspurl ){
  29. Videoview. setvideouri (URI. parse (rtspurl ));
  30. Videoview. requestfocus ();
  31. Videoview. Start ();
  32. }
  33. }



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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.