国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
使用Vitamio打造自己的Android萬能播放器(9)

前言

如果不想自己去找視頻看,以傳統(tǒng)方式看電視也不錯(cuò),比如CCTV、湖南衛(wèi)視等。本章從網(wǎng)絡(luò)收集幾百個(gè)電視臺(tái)的地址,采用多級(jí)分類方式呈現(xiàn),極大豐富在線播放部分的內(nèi)容。

聲明
  歡迎轉(zhuǎn)載,但請(qǐng)保留文章原始出處:) 
    博客園:http://www.cnblogs.com
    農(nóng)民伯伯: http://over140.cnblogs.com 
系列
  4、使用Vitamio打造自己的Android萬能播放器(4)——本地播放(快捷搜索、數(shù)據(jù)存儲(chǔ))
  5、使用Vitamio打造自己的Android萬能播放器(5)——在線播放(播放優(yōu)酷視頻)

  7、使用Vitamio打造自己的Android萬能播放器(7)——在線播放(下載視頻)

  8、使用Vitamio打造自己的Android萬能播放器(8)——細(xì)節(jié)優(yōu)化

 


正文

一、目標(biāo)

以多級(jí)目錄分類方式在在線視頻欄目下添加電視臺(tái)。


、主要代碼

電視臺(tái)的地址目前是存在XML文件里,那么本文代碼主要就是解析XML的數(shù)據(jù)了。


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;

/** 從XML讀取電視臺(tái)節(jié)目 */
public class XmlReaderHelper {

    /** 獲取所有電視分類 */
    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();
            // xml file 放到 assets目錄中的
            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;
    }

    /** 讀取分類下所有電視地址 */
    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();
            // xml file 放到 assets目錄中的
            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;
    }

 

三、下載

   請(qǐng)移步#Taocode(SVN):

   項(xiàng)目地址:http://code.taobao.org/p/oplayer

SVN地址:http://code.taobao.org/svn/oplayer/ 

 

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Android讀寫XML(上)——package說明
java 列表轉(zhuǎn)樹形
博客園 - zhuweisky - 路徑規(guī)劃(最短路徑)算法C#實(shí)現(xiàn)
html parser
定時(shí)抓取特定網(wǎng)站內(nèi)容
用DOM/JDOM解析XML文件
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服