Android multimedia learning 14th: playing online videos

Source: Internet
Author: User

Android supports Playing videos on the network. When playing a video on the network, it involves video stream transmission. there are usually two Protocols: HTTP and RTSP. This

The biggest difference between the two Protocols is that HTTP does not support real-time streaming media playback, whereas RTSP does.

 

Android player and videoview all support the above two protocols. Therefore, you can directly play videos on the network. The only difference is Uri.

 

The Code is as follows:

 

Package demo. camera; <br/> Import android. app. activity; <br/> Import android.net. uri; <br/> Import android. OS. bundle; <br/> Import android. OS. environment; <br/> Import android. widget. mediacontroller; <br/> Import android. widget. videoview; <br/>/** <br/> * This example shows how to play a video on the network in Android. The video transmission protocol is involved here, knowledge points such as video codec <br/> * @ author administrator <br/> * Android currently supports two protocols for transmitting video streams: HTTP, the other is the RTSP protocol <br/> * the HTTP protocol is most commonly used for video download, Currently, live streaming media does not support simultaneous transmission and playback. <br/> * at the same time, You must select an appropriate encoding method based on different network methods when using HTTP to transmit videos, <br/> * For example, for a GPRS network, the bandwidth is only 20 kbps, and the video stream transmission speed must be within this range. <Br/> * For example, if the multimedia encoding speed is 400 kbps for GPRS, it takes 20 seconds for a video in one second. This is obviously intolerable <br/> * during HTTP download, the file is cached on the device. The video can be played only when the file is cached to a certain extent. <Br/> * therefore, you can use the HTTP protocol when real-time playback is not required. <br/> * rtsp: real Time Streaming protocal, Real-Time Streaming Media transmission control protocol. <Br/> * When RTSP is used, the streaming media format must be RTP. <Br/> * RTSP and RTP are used in combination. RTP is not available in Android. <Br/> * RTSP and RTP are designed for Real-Time Streaming Media and support simultaneous transmission and playback. <Br/> * for different network types (such as GPRS and 3G), the RTSP encoding speed varies greatly. <Br/> * You can play videos on the network by using the three methods described above, the only difference is Uri <br/> * in this example, videoview is used to play videos on the network. <br/> */<br/> public class internetvideodemo extends activity {</P> <p> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> This. setcontentview (R. layout. video_view); </P> <p> URI uri = Uri. parse ("rtsp: // example"); <br/> videoview = (videoview) This. findviewbyid (R. id. video_view); <br/> videoview. setmediacontroller (New mediacontroller (this); <br/> videoview. setvideouri (URI); <br/> // videoview. start (); <br/> videoview. requestfocus (); <br/>}< br/>

Related Article

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.