Use Vitamio to create your Android universal player (9)-Online playback (online TV)

Source: Internet
Author: User

 

Preface

If you don't want to watch videos on your own, you can watch TV in the traditional way, such as CCTV and Hunan TV. This chapter collects the addresses of hundreds of TV stations on the Internet and presents them in multi-level classification mode, greatly enriching the content of online playback.

 

StatementWelcome to repost, but please keep the original source of the article :) blog Park: http://www.cnblogs.com farmer UNCLE: http://over140.cnblogs.com

Series1. Use Vitamio to build your Android universal player (1) -- Preparation 2. Use Vitamio to build your Android universal player (2) -- gesture control brightness, volume, scaling 3. Use Vitamio to create your own Android universal player (3)-local playback (main interface, video List)

4. Use Vitamio to create your Android universal player (4)-local playback (quick search and data storage)
5. Use Vitamio to build your Android universal player (5)-Online playback (playing Youku videos)
6. Use Vitamio to create your Android universal player (6)-Online playback (playlist)

7. Use Vitamio to create your Android universal player (7)-Online playback (download video)

8. Use Vitamio to build your Android universal player (8)-Detail Optimization

 

Body

I. Objectives

Add a TV station under an online video topic by using multi-level directory classification.

 

 

Ii. Main Code

The TV station address is currently in an XML file, so the code in this article is mainly to parse XML data.

Package com. nmbb. oplayer. ui. helper;

Import java. io. IOException;
Import java. util. ArrayList;

Import javax. xml. parsers. DocumentBuilder;
Import javax. xml. parsers. DocumentBuilderFactory;
Import javax. xml. parsers. ParserConfigurationException;

Import org. w3c. dom. Document;
Import org. w3c. dom. Element;
Import org. w3c. dom. NamedNodeMap;
Import org. w3c. dom. Node;
Import org. w3c. dom. NodeList;
Import org. xml. sax. SAXException;

Import android. content. Context;

Import com. nmbb. oplayer. po. OnlineVideo;

/** Read TV programs from XML */
Public class XmlReaderHelper {

/** Retrieve all TV Categories */
Public static ArrayList <OnlineVideo> getAllCategory (final Context context ){
ArrayList <OnlineVideo> result = new ArrayList <OnlineVideo> ();
DocumentBuilderFactory docBuilderFactory = null;
DocumentBuilder docBuilder = null;
Document doc = null;
Try {
DocBuilderFactory = DocumentBuilderFactory. newInstance ();
DocBuilder = docBuilderFactory. newDocumentBuilder ();
// Put the xml file in the assets Directory
Doc = docBuilder. parse (context. getResources (). getAssets ()
. Open ("online. xml "));
// Root element
Element root = doc. getDocumentElement ();
NodeList nodeList = root. getElementsByTagName ("category ");
For (int I = 0; I <nodeList. getLength (); I ++ ){
Node node = nodeList. item (I); // category
OnlineVideo ov = new OnlineVideo ();
NamedNodeMap attr = node. getAttributes ();
Ov. title = attr. getNamedItem ("name"). getNodeValue ();
Ov. id = attr. getNamedItem ("id"). getNodeValue ();
Ov. category = 1;
Ov. level = 2;
Ov. is_category = true;
Result. add (ov );
// Read Node
}
} Catch (IOException e ){
} Catch (SAXException e ){
} Catch (ParserConfigurationException e ){
} Finally {
Doc = null;
DocBuilder = null;
DocBuilderFactory = null;
}
Return result;
}

/** Read all TV addresses under the category */
Public static ArrayList <OnlineVideo> getVideos (final Context context,
String categoryId ){
ArrayList <OnlineVideo> result = new ArrayList <OnlineVideo> ();
DocumentBuilderFactory docBuilderFactory = null;
DocumentBuilder docBuilder = null;
Document doc = null;
Try {
DocBuilderFactory = DocumentBuilderFactory. newInstance ();
DocBuilder = docBuilderFactory. newDocumentBuilder ();
// Put the xml file in the assets Directory
Doc = docBuilder. parse (context. getResources (). getAssets ()
. Open ("online. xml "));
// Root element
Element root = doc. getElementById (categoryId );
If (root! = Null ){
NodeList nodeList = root. getChildNodes ();
For (int I = 0, j = nodeList. getLength (); I <j; I ++ ){
Node baseNode = nodeList. item (I );

If (! "Item". equals (baseNode. getNodeName ()))
Continue;
String id = baseNode. getFirstChild (). getNodeValue ();
If (id = null)
Continue;
OnlineVideo ov = new OnlineVideo ();
Ov. id = id;

Element el = doc. getElementById (ov. id );
If (el! = Null ){
Ov. title = el. getAttribute ("title ");
Ov. icon_url = el. getAttribute ("image ");
Ov. level = 3;
Ov. category = 1;
NodeList nodes = el. getChildNodes ();
For (int m = 0, n = nodes. getLength (); m <n; m ++ ){
Node node = nodes. item (m );
If (! "Ref". equals (node. getNodeName ()))
Continue;
String href = node. getAttributes ()
. GetNamedItem ("href"). getNodeValue ();
If (ov. url = null ){
Ov. url = href;
} Else {
If (ov. backup_url = null)
Ov. backup_url = new ArrayList <String> ();
Ov. backup_url.add (href );
}
}
If (ov. url! = Null)
Result. add (ov );
}
}
}
} Catch (IOException e ){
E. printStackTrace ();
} Catch (SAXException e ){
E. printStackTrace ();
} Catch (ParserConfigurationException e ){
E. printStackTrace ();
} Finally {
Doc = null;
DocBuilder = null;
DocBuilderFactory = null;
}
Return result;
}

}

 

Iii. Download

Step # Taocode (SVN ):

Project address: http://code.taobao.org/p/oplayer

SVN address: http://code.taobao.org/svn/oplayer/

 

Iv. Vitamio announcement

Formally established the Vitamio developer Alliance QQ group! Group Number:246969281
Note:Currently, only developers who have developed Vitamio-based products are allowed to join the application.Enter the product name and link for the reason for application!

Note: update the SDK to the new version released on September 9.

 

V. References

Android read/write XML (on) -- package Description

Live Video addresses of major TV stations

Network TV live video address collection

End

This is the first article written on the new Macbook Pro. Many are not used to it. The mouse is still discarded within one day, which is a step closer to IOS. The series of articles do not emphasize certain technologies, however, multiple technologies are involved as much as possible. Only by fully understanding various technologies can appropriate technologies be used as appropriate. Optimization is implemented first, so you don't have to worry about every detail in one step.

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.