0%

Jsoup地址以及相关文档:https://jsoup.org/

NewsyunUtils
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 /**
* 1.根据后台返回的json数据得到contentText
* 2.ContentText解析成Document
* 3.遍历得到所有的视频标签<video></video>以及音频标签<audio></audio>
* 4.判断src是否为相对地址,如果是修改为添加域名的绝对地址
* 5.移除所有标签中无效的属性和参数
* 6.返回处理过后body当中的内容
* <p>
* //String audioNew = newContentText.replace(audio.toString(),"<audio controls=\"controls\" width=\"100%\" height=\"50px\" src=\"http://10.9.1.11:8888/newsyun/u/cms/www/201712/20171220075904860.mp3\"></audio>");
* //String videoNew = newContentText.replace(video.toString(),"<video controls=\"controls\" width=\"100%\" height=\"200px\" src=\"http://10.9.1.11:8888/newsyun/u/cms/www/201712/20171220075834530.mp4\"></video>");
* //<video controls="controls" width="480" height="400" src="/newsyun/u/cms/www/201712/20171220075834530.mp4"></video>
*
* @param contentText
*/
public static String handleContentBodyHtml(String contentText) {
Document document = Jsoup.parse(contentText);
Element body = document.body();

Elements imgs = body.getElementsByTag("img");
for (Element img : imgs) {
if (!img.attr("src").startsWith("http") && !img.attr("src").startsWith("https")) {
img.attr("src", HttpConstants.HOST_IP + img.attr("src"));
}
}

Elements objects = body.getElementsByTag("object");
for (Element object : objects) {
String nodeName = object.parentNode().nodeName();
//判断后台给予的object对象的父节点是什么,body,video,audio
if (nodeName.equals("body")) { //说明后台是格式化一键排版之后的代码
//如果不是body,说明是在video或者audio里面的属性
// if (object.attr("src").endsWith("mp3")){
// object.toString().replace(object.toString(),"<audio controls=\"controls\" width=\"100%\" height=\"50px\" src=\"http://10.9.1.11:8888/newsyun/u/cms/www/201712/20171220075904860.mp3\");
// }else{
//
// }
}
}

//获取body中所有audio的元素
Elements audios = body.getElementsByTag("audio");
for (Element audio : audios) {
if (!audio.attr("src").startsWith("http") && !audio.attr("src").startsWith("https")) {
audio.attr("src", HttpConstants.HOST_IP + audio.attr("src"));
}
audio.removeAttr("style");
audio.removeAttr("loop");
audio.removeAttr("autoplay");
audio.addClass("newsyun_video_or_audio");
audio.attr("id", "newsyun_video_or_audio");
audio.children().remove();
audio.attr("width", "100%");
audio.attr("height", "50px");
}

//获取body中所有video的元素,遍历所有的标签
Elements videos = body.getElementsByTag("video");
for (Element video : videos) {
if (!video.attr("src").startsWith("http") && !video.attr("src").startsWith("https")) {
video.attr("src", HttpConstants.HOST_IP + video.attr("src"));
}
video.removeAttr("style");
video.removeAttr("loop");
video.removeAttr("autoplay");
video.addClass("newsyun_video_or_audio");
video.attr("id", "newsyun_video_or_audio");
video.children().remove();
video.attr("width", "100%");
video.attr("height", "200px");

}
//return body.children().toString();
return body.toString();
}
Read more »

IjkPlayerLibrary

B站开源播放器编译库(20160819),版本为Ijkplayer-k0.6.0

Ubuntu环境下编译B站开源视频播放器

编译前准备

Linux环境:本地使用Ubuntu Kylin 15.10
下载Linux:Java JDK,Android SDK,Android NDK,Git

Ps:由于需要编译ffmpeg,所以在配置环境变量后要保证足够磁盘空间

原来配置android-ndk-r11b 编译过程中报错:需要android-ndk-r10e及其之后的版本
Read more »

TagCloud