Android TV Development (10) online video streaming of Smart TV development

Source: Internet
Author: User


Reprint Annotated Source: http://blog.csdn.net/sk719887916/article/details/46582987

From < Android TV (eight) mobile intelligent terminal Multimedia Online loading web video source > I summed up how to parse a Web page, get the data inside the display, how to play video, today will give you a simple introduction of the common video open source framework Vitamio, Project SDK address:https://www.vitamio.org/en/.



decompression Vitamio SDK can see a initactivity sub-module, can be added to our project, of course, you can copy the code to their own projects, then we play the activity inherited initactivity can be, Of course we also need to use the Vparser package to interpret the video address shown in the previous article to the real address for playback, its code is as follows.

public class Playactivity extends Activity {private Videoview mvideoview;private string murl;private string path = "";p Riv Ate String mrealurl;private vparser mvparser; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); if (! Libschecker.checkvitamiolibs (This)) Return;setcontentview (r.layout.activity_one); Mvideoview = (VideoView) Findviewbyid (r.id.surface_view); mrealurl = "http://222.73.3.75/vkp.tc.qq.com/c0013ghdds8.mp4?vkey= cba83e4b773db0dbb3c5010896c3e4938c700ef47ac30134f2fd8c300e3d57b857508af5a0418d53&br=66&platform=0& Fmt=mp4&level=3 "; Mvideoview.setvideopath (Mrealurl);//mvideoview.setmediacontroller (New MediaController ( Playactivity.this)); Mvideoview.requestfocus (); Mvideoview.setonpreparedlistener (new Mediaplayer.onpreparedlistener () {@Overridepublic void onprepared (MediaPlayer MediaPlayer) {//optional need Vitamio 4.0mediaplayer.setplaybackspeed (1.0f);}});  Mvparser = new Vparser (this); if (Getintent (). Getstringextra ("url")! = null) {Murl = Getintent (). Getstringextra ("url");//murl = "http://v.iask.com/v_play_ipad.php?vid=121242141"; new Asynctask<object, Void, video> () {@Overrideprotected Video doinbackground (Object ... params) {return Mvparser.parse (string.valueof (Params[0));} @Overrideprotected void OnPostExecute (Video result) {Super.onpostexecute (result); String title = Result.title;if (Result! = null) {Mrealurl = Result.videouri; LOG.I ("Mplay", "Result.videouri:" + mrealurl); String website = result.videositeuri;if (Mrealurl = = null) {Mrealurl = "http://222.73.3.75/vkp.tc.qq.com/ C0013ghdds8.mp4?vkey=cba83e4b773db0dbb3c5010896c3e4938c700ef47ac30134f2fd8c300e3d57b857508af5a0418d53&br= 66&platform=0&fmt=mp4&level=3 ";} Mrealurl = "http://222.73.3.75/vkp.tc.qq.com/c0013ghdds8.mp4?vkey= cba83e4b773db0dbb3c5010896c3e4938c700ef47ac30134f2fd8c300e3d57b857508af5a0418d53&br=66&platform=0& Fmt=mp4&level=3 "; Mvideoview.setvideopath (Mrealurl);//mvideoview.setmediacontroller (New MediAcontroller (Playactivity.this)); Mvideoview.requestfocus (); Mvideoview.setonpreparedlistener (new Mediaplayer.onpreparedlistener () {@Overridepublic void onprepared (MediaPlayer MediaPlayer) {//optional need Vitamio 4.0mediaplayer.setplaybackspeed (1.0f);}});}. Execute (murl);}} @SuppressLint ("Newapi") Private String Getvideorealurl (string href) {video video = new Vparser (this). Parse (href);// String videotitle = Video.title; String Mrealurl = null;if (video = null) {Mrealurl = Video.videouri;if (Mrealurl.isempty ()) {return href;} else {return m Realurl;}} return href;}

Layout file, relatively simple, videoviewIo.vov.vitamio.widget. Videoview, as follows.

<merge xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http://schemas.android.com/ Tools "tools:context=".        Playactivity "> <scrollview android:id=" @+id/login_form "android:layout_width=" Match_parent "            android:layout_height= "Match_parent" > <linearlayout style= "@style/loginformcontainer" android:orientation= "vertical" > <io.vov.vitamio.widget.videoview android:id= "@+id/surfac            E_view "android:layout_width=" match_parent "android:layout_height=" Match_parent "/>                <button android:id= "@+id/sign_in_button" android:layout_width= "Wrap_content"                android:layout_height= "Wrap_content" android:text= "Play"/> <textview Android:id= "@+id/email" android:layout_width= "match_parent" android:layout_height= "Wrap_co  Ntent "              android:hint= "Broadcasting" android:maxlines= "1" android:singleline= "true"/>                <textview android:id= "@+id/password" android:layout_width= "Match_parent"                android:layout_height= "Wrap_content" android:hint= "" android:maxlines= "1" Android:singleline= "true"/> </LinearLayout> </ScrollView></merge>


  OK so this simple playback function has been completed, from the beginning of the UI building, to loading server video data, to the analysis of the show, to the final playback, this series is simply completed the entire process, a lot of details need to be researched and perfected by the reader, If you need some special palace function suggest custom Videoview, it can inherit SURFACEVIEW&NBSP; implements    mediacontroller.mediaplayercontrol, specific code can refer to io.vov.vitamio.widget. videoview.

Copyright NOTICE: This article for Bo Master original article, please respect the original, reproduced please indicate the address.

Android TV Development (10) online video streaming of Smart TV development

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.