写了一个安卓的在线播放各个电视台的小demo,放在手机和电视上都能看,但资源写在string.xml里感觉挺low 还是转成json吧,维护起来方便些,或放在服务端也挺好,一个一个修改感觉好枯燥,就用代码吧 其实这个算很简单的,只是借此复习一下
流的操作
和字符串分割
以及json的生成
和json的解析
额外说一点:这里的播放源目前都是可用的哦,使用直播流的软件就能看相应的电视台了
{
"name": "CCTV1 综合HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226489/index.m3u8",
"mdTime": "2018-10-22"
},
张风捷特烈.png
<item>CCTV1 综合HD★http://112.50.243.7/PLTV/88888888/224/3221226489/index.m3u8</item>
<item>CCTV2 财经HD★http://112.50.243.7/PLTV/88888888/224/3221226554/index.m3u8</item>
<item>CCTV-3 综艺HD★http://183.207.249.5/PLTV/3/224/3221225588/index.m3u8</item>
<item>CCTV4 中文国际★http://112.50.243.7/PLTV/88888888/224/3221226511/index.m3u8</item>
<item>CCTV-5 体育HD★http://183.207.249.15/PLTV/3/224/3221225604/index.m3u8</item>
<item>CCTV-6 电影HD★http://183.207.249.15/PLTV/3/224/3221225548/index.m3u8</item>
<item>CCTV-7 军事与农业HD★http://183.207.249.15/PLTV/3/224/3221225546/index.m3u8</item>
<item>CCTV8 电视剧HD★http://223.110.245.167/ott.js.chinamobile.com/PLTV/3/224/3221227204/index.m3u8</item>
<item>CCTV9 记录HD★http://112.50.243.7/PLTV/88888888/224/3221226566/index.m3u8</item>
<item>CCTV10 科教HD★http://112.50.243.7/PLTV/88888888/224/3221226488/index.m3u8</item>
<item>CCTV11 戏曲HD★http://112.50.243.7/PLTV/88888888/224/3221226493/index.m3u8</item>
<item>CCTV12 HD★http://112.50.243.7/PLTV/88888888/224/3221226623/index.m3u8</item>
<item>CCTV13 新闻HD★http://112.50.243.7/PLTV/88888888/224/3221226507/index.m3u8</item>
<item>CCTV14 少儿HD★http://112.50.243.7/PLTV/88888888/224/3221226497/index.m3u8</item>
<item>CCTV-15 音乐★http://183.207.249.7/PLTV/3/224/3221225568/index.m3u8</item>
<item>安徽卫视HD★http://183.207.249.15/PLTV/3/224/3221225634/index.m3u8</item>
<item>北京卫视HD★http://183.207.249.7/PLTV/3/224/3221225574/index.m3u8</item>
<item>湖南卫视 HD★http://223.110.243.173/PLTV/3/224/3221227220/index.m3u8</item>
<item>浙江卫视 HD★http://223.110.243.173/PLTV/3/224/3221227215/index.m3u8</item>
<item>青海卫视★http://183.207.249.7/PLTV/3/224/3221225580/index.m3u8</item>
<item>山东卫视★http://183.207.249.7/PLTV/3/224/3221225586/index.m3u8</item>
<item>江西卫视★http://183.207.249.15/PLTV/3/224/3221225537/index.m3u8</item>
<item>兵团卫视HD★http://v.btzx.com.cn:1935/live/weishi.stream/playlist.m3u8</item>
<item>东方卫视HD★http://111.48.34.182/huaweicdn.hb.chinamobile.com/PLTV/88888888/224/3221225810/1.m3u8?icpid=88888888&from=1&hms_devid=1143</item>
<item>河北卫视★http://183.207.249.7/PLTV/3/224/3221225602/index.m3u8</item>
<item>新疆卫视★http://183.207.249.15/PLTV/3/224/3221225523/index.m3u8</item>
<item>四川卫视★http://183.207.249.15/PLTV/3/224/3221225570/index.m3u8</item>
<item>西藏卫视★http://183.207.249.15/PLTV/3/224/3221225579/index.m3u8</item>
<item>爱情喜剧★http://183.207.249.15/PLTV/3/224/3221225525/index.m3u8</item>
<item>武林外传★http://dlhls.cdn.zhanqi.tv/zqlive/33765_6qakZ.m3u8</item>
<item>CNTV古装剧场★http://183.207.249.7/PLTV/3/224/3221225527/index.m3u8</item>
<item>动画王国HD★http://183.207.249.15/PLTV/3/224/3221225555/index.m3u8</item>
<item>海外剧场★http://183.207.249.15/PLTV/3/224/3221225547/index.m3u8</item>
<item>完美游戏★http://183.207.249.15/PLTV/3/224/3221225539/index.m3u8</item>
<item>电影轮播★http://112.50.243.7/PLTV/88888888/224/3221226670/index.m3u8</item>
<item>金鹰纪实HD★http://112.50.243.7/PLTV/88888888/224/3221226613/index.m3u8</item>
1).新建一个maven管理的java项目,引入gson依赖 2).用文件读流+bufferd包装类一行一行读取data.txt,对每行的字符串切割 3).建一个实体类,每读一行将数据加载如实体类 4).将实体类集合输出成Json格式字符串,并通过文件写流+bufferd写出
<!-- 为简化set,get,toString代码引入lombok -->
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<scope>provided</scope>
</dependency>
<!--gson依赖-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
public class OnlineVideo {
public static void main(String[] args) throws IOException {
//读取文件
String path = "I:\\Java\\SpringBoot\\small_project\\src\\main\\resources\\data.txt";
BufferedReader br = new BufferedReader(new FileReader(path));
ArrayList<VideoBean> videoBeans = new ArrayList<VideoBean>();
String line = "";
while ((line = br.readLine()) != null) {
String res = line.split(">")[1].split("<")[0];
VideoBean videoBean = new VideoBean();
videoBean.setName(res.split("★")[0]);
videoBean.setUrl(res.split("★")[1]);
videoBean.setMdTime(new SimpleDateFormat("YYYY-MM-dd").format(System.currentTimeMillis()));
videoBeans.add(videoBean);
}
br.close();
String json = new GsonBuilder().create().toJson(videoBeans);
String target = "I:\\Java\\SpringBoot\\small_project\\src\\main\\resources\\data.json";
FileWriter fileWriter = new FileWriter(target);
fileWriter.write(json);
fileWriter.close();
}
}
[
{
"name": "CCTV1 综合HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226489/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV2 财经HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226554/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV-3 综艺HD",
"url": "http://183.207.249.5/PLTV/3/224/3221225588/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV4 中文国际",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226511/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV-5 体育HD",
"url": "http://183.207.249.15/PLTV/3/224/3221225604/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV-6 电影HD",
"url": "http://183.207.249.15/PLTV/3/224/3221225548/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV-7 军事与农业HD",
"url": "http://183.207.249.15/PLTV/3/224/3221225546/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV8 电视剧HD",
"url": "http://223.110.245.167/ott.js.chinamobile.com/PLTV/3/224/3221227204/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV9 记录HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226566/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV10 科教HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226488/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV11 戏曲HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226493/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV12 HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226623/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV13 新闻HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226507/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV14 少儿HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226497/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CCTV-15 音乐",
"url": "http://183.207.249.7/PLTV/3/224/3221225568/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "安徽卫视HD",
"url": "http://183.207.249.15/PLTV/3/224/3221225634/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "北京卫视HD",
"url": "http://183.207.249.7/PLTV/3/224/3221225574/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "湖南卫视 HD",
"url": "http://223.110.243.173/PLTV/3/224/3221227220/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "浙江卫视 HD",
"url": "http://223.110.243.173/PLTV/3/224/3221227215/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "青海卫视",
"url": "http://183.207.249.7/PLTV/3/224/3221225580/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "山东卫视",
"url": "http://183.207.249.7/PLTV/3/224/3221225586/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "江西卫视",
"url": "http://183.207.249.15/PLTV/3/224/3221225537/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "兵团卫视HD",
"url": "http://v.btzx.com.cn:1935/live/weishi.stream/playlist.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "东方卫视HD",
"url": "http://111.48.34.182/huaweicdn.hb.chinamobile.com/PLTV/88888888/224/3221225810/1.m3u8?icpid\u003d88888888\u0026#038;from\u003d1\u0026#038;hms_devid\u003d1143",
"mdTime": "2018-10-22"
},
{
"name": "河北卫视",
"url": "http://183.207.249.7/PLTV/3/224/3221225602/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "新疆卫视",
"url": "http://183.207.249.15/PLTV/3/224/3221225523/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "四川卫视",
"url": "http://183.207.249.15/PLTV/3/224/3221225570/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "西藏卫视",
"url": "http://183.207.249.15/PLTV/3/224/3221225579/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "爱情喜剧",
"url": "http://183.207.249.15/PLTV/3/224/3221225525/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "武林外传",
"url": "http://dlhls.cdn.zhanqi.tv/zqlive/33765_6qakZ.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "CNTV古装剧场",
"url": "http://183.207.249.7/PLTV/3/224/3221225527/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "动画王国HD",
"url": "http://183.207.249.15/PLTV/3/224/3221225555/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "海外剧场",
"url": "http://183.207.249.15/PLTV/3/224/3221225547/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "完美游戏",
"url": "http://183.207.249.15/PLTV/3/224/3221225539/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "电影轮播",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226670/index.m3u8",
"mdTime": "2018-10-22"
},
{
"name": "金鹰纪实HD",
"url": "http://112.50.243.7/PLTV/88888888/224/3221226613/index.m3u8",
"mdTime": "2018-10-22"
}
]
可以放在服务器上,用网络访问,这里就放在assets目录下测试 添加依赖
implementation 'com.google.code.gson:gson:2.2.4'
/**
* 作者:张风捷特烈<br/>
* 时间:2018/10/22 0022:21:03<br/>
* 邮箱:1981462002@qq.com<br/>
* 说明:json解析的实体类
*/
public class VideoBean {
/**
* name : CCTV1 综合HD
* url : http://112.50.243.7/PLTV/88888888/224/3221226489/index.m3u8
* mdTime : 2018-10-22
*/
private String name;
private String url;
private String mdTime;
public static VideoBean objectFromData(String str) {
return new Gson().fromJson(str, VideoBean.class);
}
public static List<VideoBean> arrayVideoBeanFromData(String str) {
Type listType = new TypeToken<ArrayList<VideoBean>>() {
}.getType();
return new Gson().fromJson(str, listType);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMdTime() {
return mdTime;
}
public void setMdTime(String mdTime) {
this.mdTime = mdTime;
}
String json = FileHelper.get().readInAssets(this, "data.json");
List<VideoBean> videoBeans = VideoBean.arrayVideoBeanFromData(json);
mIdLvVideo.setAdapter(new MyLVAdapter<VideoBean>(this, videoBeans, R.layout.item_text_only) {
@Override
public void setData(MyLVHolder holder, VideoBean data, int position) {
holder.setText(R.id.id_tv_name, data.getName());
}
});
listView.png
项目源码 | 日期 | 备注 |
---|---|---|
V0.1--无 | 2018-10-22 | 小案例Josn字符串的生成 |