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
d71707f2
authored
Jan 11, 2017
by
Julian Cable
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Make constructor clearer
parent
8ae8ac79
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
17 deletions
library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java
library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java
library/src/main/java/com/google/android/exoplayer2/text/ssa/SSASubtitle.java
library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java
View file @
d71707f2
...
...
@@ -25,6 +25,7 @@ import com.google.android.exoplayer2.text.webvtt.Mp4WebvttDecoder;
import
com.google.android.exoplayer2.text.webvtt.WebvttDecoder
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
java.io.UnsupportedEncodingException
;
import
java.util.List
;
import
static
android
.
R
.
attr
.
initialKeyguardLayout
;
...
...
@@ -83,9 +84,9 @@ public interface SubtitleDecoderFactory {
}
if
(
clazz
==
SSADecoder
.
class
)
{
byte
[]
header
=
format
.
initializationData
.
get
(
1
);
byte
[]
dialogueFormat
=
format
.
initializationData
.
get
(
0
);
return
clazz
.
asSubclass
(
SubtitleDecoder
.
class
).
getConstructor
(
byte
[].
class
,
byte
[]
.
class
)
.
newInstance
(
header
,
d
ialogueForma
t
);
String
dlgfmt
=
new
String
(
format
.
initializationData
.
get
(
0
),
"UTF-8"
);
return
clazz
.
asSubclass
(
SubtitleDecoder
.
class
).
getConstructor
(
byte
[].
class
,
String
.
class
)
.
newInstance
(
header
,
d
lgfm
t
);
}
if
(
clazz
==
Cea608Decoder
.
class
)
{
return
clazz
.
asSubclass
(
SubtitleDecoder
.
class
).
getConstructor
(
String
.
class
,
Integer
.
TYPE
)
...
...
library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java
View file @
d71707f2
...
...
@@ -70,20 +70,16 @@ public class SSADecoder extends SimpleSubtitleDecoder {
private
String
[]
dialogueFormat
=
null
;
private
String
[]
styleFormat
=
null
;
private
Map
<
String
,
Style
>
styles
=
new
HashMap
<>();
private
final
static
long
_1e6
=
1000000
;
public
SSADecoder
()
{
super
(
"SSADecoder"
);
}
public
SSADecoder
(
byte
[]
header
,
byte
[]
dialogueFormatBytes
)
{
public
SSADecoder
(
byte
[]
header
,
String
dlgfmt
)
{
super
(
"SSADecoder"
);
decodeHeader
(
header
,
header
.
length
);
try
{
dialogueFormat
=
parseKeys
(
new
String
(
dialogueFormatBytes
,
"UTF-8"
));
}
catch
(
UnsupportedEncodingException
e
)
{
// can't happen?
}
dialogueFormat
=
parseKeys
(
dlgfmt
);
}
/**
...
...
@@ -203,7 +199,7 @@ public class SSADecoder extends SimpleSubtitleDecoder {
s
.
append
(
","
);
long
endUs
=
durationUs
;
// + blockTimeUs
if
(
endUs
==
C
.
TIME_UNSET
)
{
endUs
=
2
000000
;
// 2 second default duration
endUs
=
2
*
_1e6
;
// 2 second default duration
}
s
.
append
(
SSADecoder
.
formatTimeCode
(
endUs
));
s
.
append
(
","
);
...
...
@@ -213,13 +209,13 @@ public class SSADecoder extends SimpleSubtitleDecoder {
}
public
static
String
formatTimeCode
(
long
tc_us
)
{
long
seconds
=
tc_us
/
1000000
;
long
us
=
tc_us
-
1000000
*
seconds
;
long
seconds
=
tc_us
/
_1e6
;
long
us
=
tc_us
-
_1e6
*
seconds
;
long
minutes
=
seconds
/
60
;
seconds
-=
60
*
minutes
;
long
hours
=
minutes
/
60
;
minutes
-=
60
*
hours
;
double
sec
=
seconds
+
((
float
)
us
)/
1000000.0
;
double
sec
=
seconds
+
((
float
)
us
)/
_1e6
;
return
String
.
format
(
Locale
.
US
,
"%01d:%02d:%06.3f"
,
hours
,
minutes
,
sec
);
}
...
...
@@ -228,8 +224,8 @@ public class SSADecoder extends SimpleSubtitleDecoder {
long
hours
=
Long
.
parseLong
(
p
[
0
]);
long
minutes
=
Long
.
parseLong
(
p
[
1
]);
float
seconds
=
Float
.
parseFloat
(
p
[
2
]);
float
us
=
1000000
*
seconds
;
float
us
=
_1e6
*
seconds
;
long
lus
=
((
long
)
us
);
return
lus
+
1000000
*
(
60
*
(
minutes
+
60
*
hours
));
return
lus
+
_1e6
*
(
60
*
(
minutes
+
60
*
hours
));
}
}
library/src/main/java/com/google/android/exoplayer2/text/ssa/SSASubtitle.java
View file @
d71707f2
...
...
@@ -12,6 +12,7 @@ import java.util.List;
import
java.util.Map
;
import
static
android
.
R
.
attr
.
start
;
import
static
android
.
os
.
Build
.
VERSION_CODES
.
N
;
/**
* Created by cablej01 on 26/12/2016.
...
...
@@ -92,6 +93,7 @@ public class SSASubtitle implements Subtitle {
int
layer
=
Integer
.
parseInt
(
ev
.
get
(
"layer"
));
String
effect
=
ev
.
get
(
"effect"
);
String
text
=
ev
.
get
(
"text"
).
replaceAll
(
"\\\\N"
,
"\n"
);
text
=
text
.
replaceAll
(
"\\\\n"
,
"\n"
);
String
simpleText
=
text
.
replaceAll
(
"\\{[^{]*\\}"
,
""
);
//Cue cue = new SSACue(text, style, layer, effect);
Cue
cue
=
new
Cue
(
simpleText
);
...
...
@@ -99,7 +101,7 @@ public class SSASubtitle implements Subtitle {
cueTimesUs
.
add
(
start
);
cues
.
add
(
cue
);
// add null cue to remove this cue after it's duration
long
end
=
SSADecoder
.
parseTimecode
(
ev
.
get
(
"end"
));
long
end
=
10
*
SSADecoder
.
parseTimecode
(
ev
.
get
(
"end"
));
cueTimesUs
.
add
(
end
);
cues
.
add
(
null
);
}
...
...
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