Android 使用Vitamio打造自己的萬能播放器(9)—— 在線播放 (在線電視)
前言
如果不想自己去找視頻看,以傳統(tǒng)方式看電視也不錯,比如CCTV、湖南衛(wèi)視等。本章從網(wǎng)絡(luò)收集幾百個電視臺的地址,采用多級分類方式呈現(xiàn),極大豐富在線播放部分的內(nèi)容。
系列
1、Android 使用Vitamio打造自己的萬能播放器(1)——準(zhǔn)備
2、Android 使用Vitamio打造自己的萬能播放器(2)—— 手勢控制亮度、音量、縮放
3、Android 使用Vitamio打造自己的萬能播放器(3)——本地播放(主界面、視頻列表)
4、Android 使用Vitamio打造自己的萬能播放器(4)——本地播放(快捷搜索、數(shù)據(jù)存儲)
5、Android 使用Vitamio打造自己的萬能播放器(5)——在線播放(播放優(yōu)酷視頻)
6、Android 使用Vitamio打造自己的萬能播放器(6)——在線播放(播放列表)
7、Android 使用Vitamio打造自己的萬能播放器(7)——在線播放(下載視頻)
8、Android 使用Vitamio打造自己的萬能播放器(8)——細(xì)節(jié)優(yōu)化
正文
一、目標(biāo)
以多級目錄分類方式在在線視頻欄目下添加電視臺。


二、主要代碼
電視臺的地址目前是存在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讀取電視臺節(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;
}
}
三、下載
請移步#Taocode(SVN):
項目地址:http://code.taobao.org/p/oplayer
SVN地址:http://code.taobao.org/svn/oplayer/
四、參考
Android讀寫XML(上)——package說明
各大電視臺直播地址
網(wǎng)絡(luò)電視直播地址收集
結(jié)束
本文是新入手Macbook Pro上寫的第一篇文章,諸多不習(xí)慣,仍然在一天內(nèi)成功丟棄鼠標(biāo),離IOS又近一步了:) 系列文章并不強(qiáng)調(diào)用某種技術(shù),但盡可能涉及到多種技術(shù),只有充分了解各種技術(shù)才能在適當(dāng)?shù)臅r候使用合適的技術(shù)。先實現(xiàn)后優(yōu)化,不必一步到位糾結(jié)于每個細(xì)節(jié)。
以上就是對Android Vitamio 開發(fā)播放在線電視相關(guān)資料,后續(xù)繼續(xù)補(bǔ)充。
- Android 使用Vitamio打造自己的萬能播放器(10)—— 本地播放 (縮略圖、視頻信息、視頻掃描服務(wù))
- Android 使用Vitamio打造自己的萬能播放器(8)——細(xì)節(jié)優(yōu)化
- Android 使用Vitamio打造自己的萬能播放器(7)——在線播放(下載視頻)
- Android 使用Vitamio打造自己的萬能播放器(6)——在線播放(播放列表)
- Android 使用Vitamio打造自己的萬能播放器(5)——在線播放(播放優(yōu)酷視頻)
- Android 使用Vitamio打造自己的萬能播放器(4)——本地播放(快捷搜索、數(shù)據(jù)存儲)
- Android 使用Vitamio打造自己的萬能播放器(3)——本地播放(主界面、播放列表)
- Android 使用Vitamio打造自己的萬能播放器(2)—— 手勢控制亮度、音量、縮放
- Android 使用Vitamio打造自己的萬能播放器(1)——準(zhǔn)備
- Android使用vitamio插件實現(xiàn)視頻播放器
相關(guān)文章
Android帶清除功能的輸入框控件EditTextWithDel
這篇文章主要為大家詳細(xì)介紹了Android帶清除功能的輸入框控件EditTextWithDel,感興趣的小伙伴們可以參考一下2016-09-09
Github簡單易用的?Android?ViewModel?Retrofit框架
這篇文章主要介紹了Github簡單易用的Android?ViewModel?Retrofit框架,RequestViewMode有自動對LiveData進(jìn)行緩存管理,每個retrofit api接口復(fù)用一個livedata的優(yōu)勢。下文具體詳情,感興趣的小伙伴可以參考一下2022-06-06
Android 超詳細(xì)講解fitsSystemWindows屬性的使用
fitsSystemWindows屬性可以讓view根據(jù)系統(tǒng)窗口來調(diào)整自己的布局;簡單點說就是我們在設(shè)置應(yīng)用布局時是否考慮系統(tǒng)窗口布局,這里系統(tǒng)窗口包括系統(tǒng)狀態(tài)欄、導(dǎo)航欄、輸入法等,包括一些手機(jī)系統(tǒng)帶有的底部虛擬按鍵2022-03-03
Android仿Flipboard動畫效果的實現(xiàn)代碼
這篇文章主要介紹了Android仿Flipboard動畫效果的實現(xiàn)代碼,本文圖文并茂給大家介紹的非常詳細(xì),需要的朋友可以參考下2018-01-01
如何在Android中實現(xiàn)一個簡易的Http服務(wù)器
這篇文章主要介紹了如何在Android中實現(xiàn)一個簡易的Http服務(wù)器,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05
解決AndroidStudio無法運行java中的mian方法問題
這篇文章主要介紹了解決AndroidStudio無法運行java中的mian方法問題,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10
android ViewPager實現(xiàn)自動無限輪播和下方向?qū)A點
本篇文章主要介紹了android ViewPager實現(xiàn)自動輪播和下方向?qū)A點,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-02-02
Android?Studio調(diào)試Gradle插件詳情
這篇文章主要介紹了Android?Studio調(diào)試Gradle插件詳情,文章圍繞主題展開詳細(xì)的內(nèi)容戒殺,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09

