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
741a9c2e
authored
Feb 21, 2021
by
Arnold Szabo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add support for font size in SSA v4+ styling.
parent
1a12018d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
4 deletions
demos/main/src/main/assets/media.exolist.json
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaStyle.java
demos/main/src/main/assets/media.exolist.json
View file @
741a9c2e
...
@@ -507,6 +507,13 @@
...
@@ -507,6 +507,13 @@
"subtitle_language"
:
"en"
"subtitle_language"
:
"en"
},
},
{
{
"name"
:
"SubStation Alpha font size"
,
"uri"
:
"https://storage.googleapis.com/exoplayer-test-media-1/gen-3/screens/dash-vod-single-segment/video-avc-baseline-480.mp4"
,
"subtitle_uri"
:
"https://drive.google.com/uc?export=download&id=13EdW4Qru-vQerUlwS_Ht5Cely_Tn0tQe"
,
"subtitle_mime_type"
:
"text/x-ssa"
,
"subtitle_language"
:
"en"
},
{
"name"
:
"MPEG-4 Timed Text"
,
"name"
:
"MPEG-4 Timed Text"
,
"uri"
:
"https://storage.googleapis.com/exoplayer-test-media-1/mp4/dizzy-with-tx3g.mp4"
"uri"
:
"https://storage.googleapis.com/exoplayer-test-media-1/mp4/dizzy-with-tx3g.mp4"
}
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java
View file @
741a9c2e
...
@@ -314,6 +314,11 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
...
@@ -314,6 +314,11 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
/* end= */
spannableText
.
length
(),
/* end= */
spannableText
.
length
(),
SpannableString
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
SpannableString
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
}
if
(
style
.
fontSize
!=
null
&&
screenHeight
!=
Cue
.
DIMEN_UNSET
)
{
cue
.
setTextSize
(
style
.
fontSize
/
screenHeight
,
Cue
.
TEXT_SIZE_TYPE_FRACTIONAL_IGNORE_PADDING
);
}
}
}
@SsaStyle
.
SsaAlignment
int
alignment
;
@SsaStyle
.
SsaAlignment
int
alignment
;
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/ssa/SsaStyle.java
View file @
741a9c2e
...
@@ -90,12 +90,17 @@ import java.util.regex.Pattern;
...
@@ -90,12 +90,17 @@ import java.util.regex.Pattern;
public
final
String
name
;
public
final
String
name
;
@SsaAlignment
public
final
int
alignment
;
@SsaAlignment
public
final
int
alignment
;
@Nullable
@ColorInt
public
final
Integer
primaryColor
;
@Nullable
@ColorInt
public
final
Integer
primaryColor
;
public
final
Integer
fontSize
;
private
SsaStyle
(
private
SsaStyle
(
String
name
,
@SsaAlignment
int
alignment
,
@Nullable
@ColorInt
Integer
primaryColor
)
{
String
name
,
@SsaAlignment
int
alignment
,
@Nullable
@ColorInt
Integer
primaryColor
,
Integer
fontSize
)
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
alignment
=
alignment
;
this
.
alignment
=
alignment
;
this
.
primaryColor
=
primaryColor
;
this
.
primaryColor
=
primaryColor
;
this
.
fontSize
=
fontSize
;
}
}
@Nullable
@Nullable
...
@@ -114,7 +119,8 @@ import java.util.regex.Pattern;
...
@@ -114,7 +119,8 @@ import java.util.regex.Pattern;
return
new
SsaStyle
(
return
new
SsaStyle
(
styleValues
[
format
.
nameIndex
].
trim
(),
styleValues
[
format
.
nameIndex
].
trim
(),
parseAlignment
(
styleValues
[
format
.
alignmentIndex
].
trim
()),
parseAlignment
(
styleValues
[
format
.
alignmentIndex
].
trim
()),
parseColor
(
styleValues
[
format
.
primaryColorIndex
].
trim
()));
parseColor
(
styleValues
[
format
.
primaryColorIndex
].
trim
()),
parseFontSize
(
styleValues
[
format
.
fontSizeIndex
].
trim
()));
}
catch
(
RuntimeException
e
)
{
}
catch
(
RuntimeException
e
)
{
Log
.
w
(
TAG
,
"Skipping malformed 'Style:' line: '"
+
styleLine
+
"'"
,
e
);
Log
.
w
(
TAG
,
"Skipping malformed 'Style:' line: '"
+
styleLine
+
"'"
,
e
);
return
null
;
return
null
;
...
@@ -191,6 +197,15 @@ import java.util.regex.Pattern;
...
@@ -191,6 +197,15 @@ import java.util.regex.Pattern;
return
Color
.
argb
(
a
,
r
,
g
,
b
);
return
Color
.
argb
(
a
,
r
,
g
,
b
);
}
}
private
static
Integer
parseFontSize
(
String
fontSize
)
{
try
{
return
Integer
.
parseInt
(
fontSize
);
}
catch
(
NumberFormatException
e
)
{
Log
.
w
(
TAG
,
"Failed to parse font size: '"
+
fontSize
+
"'"
,
e
);
return
null
;
}
}
/**
/**
* Represents a {@code Format:} line from the {@code [V4+ Styles]} section
* Represents a {@code Format:} line from the {@code [V4+ Styles]} section
*
*
...
@@ -202,12 +217,19 @@ import java.util.regex.Pattern;
...
@@ -202,12 +217,19 @@ import java.util.regex.Pattern;
public
final
int
nameIndex
;
public
final
int
nameIndex
;
public
final
int
alignmentIndex
;
public
final
int
alignmentIndex
;
public
final
int
primaryColorIndex
;
public
final
int
primaryColorIndex
;
public
final
int
fontSizeIndex
;
public
final
int
length
;
public
final
int
length
;
private
Format
(
int
nameIndex
,
int
alignmentIndex
,
int
primaryColorIndex
,
int
length
)
{
private
Format
(
int
nameIndex
,
int
alignmentIndex
,
int
primaryColorIndex
,
int
fontSizeIndex
,
int
length
)
{
this
.
nameIndex
=
nameIndex
;
this
.
nameIndex
=
nameIndex
;
this
.
alignmentIndex
=
alignmentIndex
;
this
.
alignmentIndex
=
alignmentIndex
;
this
.
primaryColorIndex
=
primaryColorIndex
;
this
.
primaryColorIndex
=
primaryColorIndex
;
this
.
fontSizeIndex
=
fontSizeIndex
;
this
.
length
=
length
;
this
.
length
=
length
;
}
}
...
@@ -221,6 +243,7 @@ import java.util.regex.Pattern;
...
@@ -221,6 +243,7 @@ import java.util.regex.Pattern;
int
nameIndex
=
C
.
INDEX_UNSET
;
int
nameIndex
=
C
.
INDEX_UNSET
;
int
alignmentIndex
=
C
.
INDEX_UNSET
;
int
alignmentIndex
=
C
.
INDEX_UNSET
;
int
primaryColorIndex
=
C
.
INDEX_UNSET
;
int
primaryColorIndex
=
C
.
INDEX_UNSET
;
int
fontSizeIndex
=
C
.
INDEX_UNSET
;
String
[]
keys
=
String
[]
keys
=
TextUtils
.
split
(
styleFormatLine
.
substring
(
SsaDecoder
.
FORMAT_LINE_PREFIX
.
length
()),
","
);
TextUtils
.
split
(
styleFormatLine
.
substring
(
SsaDecoder
.
FORMAT_LINE_PREFIX
.
length
()),
","
);
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
...
@@ -234,10 +257,13 @@ import java.util.regex.Pattern;
...
@@ -234,10 +257,13 @@ import java.util.regex.Pattern;
case
"primarycolour"
:
case
"primarycolour"
:
primaryColorIndex
=
i
;
primaryColorIndex
=
i
;
break
;
break
;
case
"fontsize"
:
fontSizeIndex
=
i
;
break
;
}
}
}
}
return
nameIndex
!=
C
.
INDEX_UNSET
return
nameIndex
!=
C
.
INDEX_UNSET
?
new
Format
(
nameIndex
,
alignmentIndex
,
primaryColorIndex
,
keys
.
length
)
?
new
Format
(
nameIndex
,
alignmentIndex
,
primaryColorIndex
,
fontSizeIndex
,
keys
.
length
)
:
null
;
:
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