Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fd2ebc76
authored
Jun 03, 2015
by
ood_tsen
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
keep maximum number of subtitles to four.
parent
106ebbf7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
19 deletions
library/src/main/java/com/google/android/exoplayer/text/tx3g/SubtitleData.java
library/src/main/java/com/google/android/exoplayer/text/tx3g/TextParser.java
library/src/main/java/com/google/android/exoplayer/text/tx3g/TextSubtitle.java
library/src/main/java/com/google/android/exoplayer/text/tx3g/SubtitleData.java
View file @
fd2ebc76
...
...
@@ -18,15 +18,18 @@ package com.google.android.exoplayer.text.tx3g;
import
java.util.Comparator
;
/**
* A representation of a single tx3g.
*/
class
SubtitleData
implements
Comparable
<
SubtitleData
>,
Comparator
<
SubtitleData
>
{
public
final
long
startTimePosUs
;
public
final
String
s
trS
ubtitle
;
public
final
String
subtitle
;
SubtitleData
(
long
startTimePosUs
,
String
s
trS
ubtitle
)
SubtitleData
(
long
startTimePosUs
,
String
subtitle
)
{
this
.
startTimePosUs
=
startTimePosUs
;
this
.
s
trSubtitle
=
strS
ubtitle
;
this
.
s
ubtitle
=
s
ubtitle
;
}
@Override
...
...
library/src/main/java/com/google/android/exoplayer/text/tx3g/TextParser.java
View file @
fd2ebc76
...
...
@@ -19,8 +19,6 @@ import com.google.android.exoplayer.text.Subtitle;
import
com.google.android.exoplayer.text.SubtitleParser
;
import
com.google.android.exoplayer.util.MimeTypes
;
import
android.util.Log
;
import
java.io.DataInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -40,13 +38,12 @@ public class TextParser implements SubtitleParser {
private
static
final
String
TAG
=
"TextParser"
;
private
final
List
<
SubtitleData
>
subtitleList
;
private
static
final
int
MAX_SUBTITLE_COUNT
=
4
;
public
TextParser
()
{
Log
.
i
(
TAG
,
"TextParser "
);
subtitleList
=
new
LinkedList
<
SubtitleData
>();
}
@Override
public
Subtitle
parse
(
InputStream
inputStream
,
String
inputEncoding
,
long
startTimeUs
)
throws
IOException
{
...
...
@@ -54,10 +51,13 @@ public class TextParser implements SubtitleParser {
DataInputStream
in
=
new
DataInputStream
(
inputStream
);
String
text
=
in
.
readUTF
();
text
=
(
text
==
null
)
?
""
:
text
;
Log
.
i
(
TAG
,
"parse("
+
text
+
","
+
startTimeUs
+
")"
);
SubtitleData
cue
=
new
SubtitleData
(
startTimeUs
,
text
);
while
(
subtitleList
.
size
()
>
MAX_SUBTITLE_COUNT
)
{
subtitleList
.
remove
(
0
);
}
subtitleList
.
add
(
cue
);
Collections
.
sort
(
subtitleList
,
new
Comparator
<
SubtitleData
>()
{
...
...
@@ -70,13 +70,11 @@ public class TextParser implements SubtitleParser {
return
0
;
}
});
TextSubtitle
textSubtitle
=
new
TextSubtitle
(
subtitleList
);
return
textSubtitle
;
return
new
TextSubtitle
(
subtitleList
);
}
@Override
public
boolean
canParse
(
String
mimeType
)
{
boolean
rtn
=
MimeTypes
.
APPLICATION_TX3G
.
equals
(
mimeType
);
return
rtn
;
return
MimeTypes
.
APPLICATION_TX3G
.
equals
(
mimeType
);
}
}
library/src/main/java/com/google/android/exoplayer/text/tx3g/TextSubtitle.java
View file @
fd2ebc76
...
...
@@ -34,7 +34,7 @@ public final class TextSubtitle implements Subtitle {
@Override
public
long
getStartTime
()
{
return
text
.
get
(
0
).
getStartTimePos
()
;
return
text
.
get
(
0
).
startTimePosUs
;
}
@Override
...
...
@@ -54,12 +54,12 @@ public final class TextSubtitle implements Subtitle {
public
long
getEventTime
(
int
index
)
{
if
(
index
>
text
.
size
()
-
1
)
return
-
1
;
return
text
.
get
(
index
).
getStartTimePos
()
;
return
text
.
get
(
index
).
startTimePosUs
;
}
@Override
public
long
getLastEventTime
()
{
return
text
.
get
(
0
).
getStartTimePos
()
;
return
text
.
get
(
0
).
startTimePosUs
;
}
@Override
...
...
@@ -68,7 +68,7 @@ public final class TextSubtitle implements Subtitle {
List
<
Cue
>
list
=
new
ArrayList
<>();
if
(
index
==
-
1
)
return
null
;
String
str
=
text
.
get
(
index
).
getsubtitleText
()
;
String
str
=
text
.
get
(
index
).
subtitle
;
list
.
add
(
new
Cue
(
str
));
return
list
;
...
...
@@ -80,10 +80,10 @@ public final class TextSubtitle implements Subtitle {
int
length
=
text
.
size
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
SubtitleData
data
=
text
.
get
(
i
);
boolean
bCheckFront
=
data
.
getStartTimePos
()
<=
timeUs
;
boolean
bCheckFront
=
data
.
startTimePosUs
<=
timeUs
;
boolean
bCheckEnd
=
false
;
if
(
i
+
1
<
length
)
{
bCheckEnd
=
text
.
get
(
i
+
1
).
getStartTimePos
()
>
timeUs
;
bCheckEnd
=
text
.
get
(
i
+
1
).
startTimePosUs
>
timeUs
;
}
else
if
(
i
+
1
==
length
)
{
bCheckEnd
=
true
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment