Objective
If you do not want to find the video, the traditional way to watch TV is also good, such as CCTV, Hunan TV and so on. This chapter collects hundreds of television stations from the network address, uses the multi-level classification method to present, greatly enriches the on-line broadcast part the content.
Series
1. Android uses Vitamio to build its own universal player (1)--ready
2, Android uses Vitamio to build its own universal player (2)--gesture control brightness, volume, zoom
3, Android use Vitamio to build their own universal player (3)--local playback (main interface, video list)
4, Android use Vitamio to build their own universal player (4)--Local playback (fast search, data storage)
5, Android use Vitamio to build their own universal player (5)--Play online (play cool video)
6. Android uses Vitamio to build its own universal player (6)--Play Online (playlist)
7, Android use Vitamio to build their own universal player (7)--Play Online (download video)
8, Android uses Vitamio to build its own universal player (8)--Detail optimization
Body
I. Objectives
To add the TV station in the online video column by the multilevel catalogue classification method.
Second, the main code
TV's address is currently in the XML file, then the code is mainly parsing 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 program from XML/public class Xmlreaderhelper {/** get all TV categories/public static arraylist<onlinevideo> Getallca
Tegory (Final context) {arraylist<onlinevideo> result = new arraylist<onlinevideo> ();
Documentbuilderfactory docbuilderfactory = null;
Documentbuilder docbuilder = null;
Document doc = null;
try {docbuilderfactory = Documentbuilderfactory.newinstance ();
Docbuilder = Docbuilderfactory.newdocumentbuilder (); XML file to AssDoc = Docbuilder.parse in the ETS directory (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 O
v = 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 (Parserconfigurationexceptio
n e) {} finally {doc = null;
Docbuilder = null;
Docbuilderfactory = null;
return result; /** read all TV addresses under 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 ();
The XML file is placed in the assets directory of 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;
}
}
Third, download
Please go to #taocode (SVN):
Project Address: Http://code.taobao.org/p/oplayer
SVN address: http://code.taobao.org/svn/oplayer/
Iv. Reference
Android Read and write XML (upper)--package description
Live address of all major television stations
Network TV Live Address collection
End
This article is a new start MacBook Pro on the first article, a lot of not accustomed to, still in a day to successfully discard the mouse, from iOS another step closer: A series of articles does not emphasize the use of a technology, but as far as possible involves a variety of technologies, only to fully understand the various technologies in the appropriate time to use the appropriate technology. First realize after optimization, do not have to one-step entangled in every detail.
The above is on the Android Vitamio development broadcast online TV related information, follow-up continue to add.