Android uses Videoview to play network video

Source: Internet
Author: User

Android supports playing video on the network. When playing video on the network, there are two kinds of protocols, one is HTTP and the other is RTSP, which involves the transmission of the video stream. This

The biggest difference between the two protocols is that the HTTP protocol does not support the playback of live streaming, while the RTSP protocol supports it.

Both of these protocols are supported by the player that comes with Android, as well as videoview, so you can play the video directly on the network, and the only difference is the URI.

The code is as follows:

Package Demo.camera;      Import android.app.Activity;      Import Android.net.Uri;      Import Android.os.Bundle;      Import android.os.Environment;      Import Android.widget.MediaController;      Import Android.widget.VideoView; /** * This example shows how to play video on the network in Android, where the video transmission protocol, video codec and other knowledge points are involved * @author Administrator *android currently supports two protocols for streaming video streams one is HTT P protocol, the other is the RTSP protocol *http protocol is most commonly used in video download, etc., but currently does not support the edge transmission side playback of real-time streaming media * At the same time, when using the HTTP protocol to transmit video, you need to choose the appropriate encoding method according to different network mode, * For example, GPRS network      , its bandwidth is only 20kbps, we need to make the video stream transmission speed within this range. * For example, for GPRS, if the encoding speed of multimedia is 400kbps, then for a second video, it will take 20 seconds.      This is obviously intolerable. *http when downloading, the cache is cached on the device and can only start playing if the cache is to a certain extent.      * So, in the case where real-time playback is not required, we can use the HTTP protocol * *rtsp:real time streaming protocal, live streaming Transmission Control protocol.      * When using RTSP, the format of the streaming media needs to be RTP.      *RTSP and RTP are used in conjunction, RTP alone in Android Chinese is not available.      * *RTSP and RTP are designed for real-time streaming, supporting side-transfer side playback. * * Same for different network types (gprs,3g, etc.), the encoding speed of RTSP also varies greatly. According to the actual situation * * Using the three methods described above, you can play the video on the network, the only difference is the URI * * This example uses Videoview to play video on the network*/       Public classInternetvideodemo extends Activity { Public voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);  This. Setcontentview (R.layout.video_view); Uri URI= Uri.parse ("rtsp://v2.cache2.c.youtube.com/cjgleny73wialwm3jbt_%ed%af%80%ed%b0% 819HQWOHMYESARFEIJBXYTZ29VZ2XLSARSB3JLC3VSDHNG_VSMSBESYD5JDA==/0/0/0/VIDEO.3GP"); Videoview Videoview= (Videoview) This. Findviewbyid (R.id.video_view); Videoview.setmediacontroller (NewMediacontroller ( This));              Videoview.setvideouri (URI); //Videoview.start (); Videoview.requestfocus (); }         }  

Android uses Videoview to play network video

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.