M3U8.java
2.9 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.topdraw.sohu.utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class M3U8 {
private String strBasePath;
private List<Ts> listTs = new ArrayList<>();
private long lStartTime;// 开始时间
private long lEndTime;// 结束时间
private long lStartDownloadTime;// 开始下载时间
private long lEndDownloadTime;// 结束下载时间
public String getStrBasePath() {
return strBasePath;
}
public void setStrBasePath(String strBasePath) {
this.strBasePath = strBasePath;
}
public List<Ts> getListTs() {
return listTs;
}
public void setListTs(List<Ts> listTs) {
this.listTs = listTs;
}
public void addTs(Ts ts) {
this.listTs.add(ts);
}
public long getLStartDownloadTime() {
return lStartDownloadTime;
}
public void setLStartDownloadTime(long lStartDownloadTime) {
this.lStartDownloadTime = lStartDownloadTime;
}
public long getLEndDownloadTime() {
return lEndDownloadTime;
}
public void setLEndDownloadTime(long lEndDownloadTime) {
this.lEndDownloadTime = lEndDownloadTime;
}
/**
* 获取开始时间
*
* @return
*/
public long getLStartTime() {
if (listTs.size() > 0) {
Collections.sort(listTs);
lStartTime = listTs.get(0).getLongDate();
return lStartTime;
}
return 0;
}
/**
* 获取结束时间(加上了最后一段时间的持续时间)
*
* @return
*/
public long getLEndTime() {
if (listTs.size() > 0) {
Ts tsM3U8 = listTs.get(listTs.size() - 1);
lEndTime = tsM3U8.getLongDate() + (long) (tsM3U8.getFSeconds() * 1000);
return lEndTime;
}
return 0;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("strBasePath: " + strBasePath);
for (Ts ts : listTs) {
sb.append("\nts_file_name = " + ts);
}
sb.append("\n\nlStartTime = " + lStartTime);
sb.append("\n\nlEndTime = " + lEndTime);
sb.append("\n\nlStartDownloadTime = " + lStartDownloadTime);
sb.append("\n\nlEndDownloadTime = " + lEndDownloadTime);
return sb.toString();
}
public static class Ts implements Comparable<Ts> {
private String strFilePath;
private float fSeconds;
public Ts(String strFilePath, float fSeconds) {
this.strFilePath = strFilePath;
this.fSeconds = fSeconds;
}
public String getStrFilePath() {
return strFilePath;
}
public void setStrFilePath(String strFilePath) {
this.strFilePath = strFilePath;
}
public float getFSeconds() {
return fSeconds;
}
public void setFSeconds(float fSeconds) {
this.fSeconds = fSeconds;
}
@Override
public String toString() {
return strFilePath + " (" + fSeconds + "sec)";
}
/**
* 获取时间
*/
public long getLongDate() {
try {
return Long.parseLong(strFilePath.substring(0, strFilePath.lastIndexOf(".")));
} catch (Exception e) {
return 0;
}
}
@Override
public int compareTo(Ts o) {
return strFilePath.compareTo(o.strFilePath);
}
}
}