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
2842eb3e
authored
Mar 26, 2020
by
ibaker
Committed by
Oliver Woodman
Mar 27, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Make milliseconds optional in SubRip (SRT) subtitles
issue:#7122 PiperOrigin-RevId: 303154493
parent
47d5dd91
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
9 deletions
RELEASENOTES.md
library/core/src/main/java/com/google/android/exoplayer2/text/subrip/SubripDecoder.java
library/core/src/test/java/com/google/android/exoplayer2/text/subrip/SubripDecoderTest.java
testdata/src/test/assets/subrip/typical_no_hours → testdata/src/test/assets/subrip/typical_no_hours_and_millis
RELEASENOTES.md
View file @
2842eb3e
...
...
@@ -86,7 +86,7 @@
(
[
#6885
](
https://github.com/google/ExoPlayer/issues/6885
)
).
*
Parse
`tts:ruby`
and
`tts:rubyPosition`
properties in TTML subtitles
(rendering is coming later).
*
Allow missing hours in SubRip (.srt) timecodes
*
Allow missing hours
& milliseconds
in SubRip (.srt) timecodes
(
[
#7122
](
https://github.com/google/ExoPlayer/issues/7122
)
).
*
DRM:
*
Add support for attaching DRM sessions to clear content in the demo app.
...
...
library/core/src/main/java/com/google/android/exoplayer2/text/subrip/SubripDecoder.java
View file @
2842eb3e
...
...
@@ -41,8 +41,8 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
private
static
final
String
TAG
=
"SubripDecoder"
;
// Some SRT files don't include hours
in the timecode, so we use an optional group
.
private
static
final
String
SUBRIP_TIMECODE
=
"(?:(\\d+):)?(\\d+):(\\d+)
,(\\d+)
"
;
// Some SRT files don't include hours
or milliseconds in the timecode, so we use optional groups
.
private
static
final
String
SUBRIP_TIMECODE
=
"(?:(\\d+):)?(\\d+):(\\d+)
(?:,(\\d+))?
"
;
private
static
final
Pattern
SUBRIP_TIMING_LINE
=
Pattern
.
compile
(
"\\s*("
+
SUBRIP_TIMECODE
+
")\\s*-->\\s*("
+
SUBRIP_TIMECODE
+
")\\s*"
);
...
...
@@ -235,7 +235,10 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
long
timestampMs
=
hours
!=
null
?
Long
.
parseLong
(
hours
)
*
60
*
60
*
1000
:
0
;
timestampMs
+=
Long
.
parseLong
(
matcher
.
group
(
groupOffset
+
2
))
*
60
*
1000
;
timestampMs
+=
Long
.
parseLong
(
matcher
.
group
(
groupOffset
+
3
))
*
1000
;
timestampMs
+=
Long
.
parseLong
(
matcher
.
group
(
groupOffset
+
4
));
@Nullable
String
millis
=
matcher
.
group
(
groupOffset
+
4
);
if
(
millis
!=
null
)
{
timestampMs
+=
Long
.
parseLong
(
millis
);
}
return
timestampMs
*
1000
;
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/text/subrip/SubripDecoderTest.java
View file @
2842eb3e
...
...
@@ -39,7 +39,7 @@ public final class SubripDecoderTest {
private
static
final
String
TYPICAL_NEGATIVE_TIMESTAMPS
=
"subrip/typical_negative_timestamps"
;
private
static
final
String
TYPICAL_UNEXPECTED_END
=
"subrip/typical_unexpected_end"
;
private
static
final
String
TYPICAL_WITH_TAGS
=
"subrip/typical_with_tags"
;
private
static
final
String
TYPICAL_NO_HOURS
=
"subrip/typical_no_hour
s"
;
private
static
final
String
TYPICAL_NO_HOURS
_AND_MILLIS
=
"subrip/typical_no_hours_and_milli
s"
;
@Test
public
void
decodeEmpty
()
throws
IOException
{
...
...
@@ -179,15 +179,17 @@ public final class SubripDecoderTest {
}
@Test
public
void
decodeTypicalNoHours
()
throws
IOException
{
public
void
decodeTypicalNoHours
AndMillis
()
throws
IOException
{
SubripDecoder
decoder
=
new
SubripDecoder
();
byte
[]
bytes
=
TestUtil
.
getByteArray
(
ApplicationProvider
.
getApplicationContext
(),
TYPICAL_NO_HOURS
);
TestUtil
.
getByteArray
(
ApplicationProvider
.
getApplicationContext
(),
TYPICAL_NO_HOURS_AND_MILLIS
);
Subtitle
subtitle
=
decoder
.
decode
(
bytes
,
bytes
.
length
,
false
);
assertThat
(
subtitle
.
getEventTimeCount
()).
isEqualTo
(
6
);
assertTypicalCue1
(
subtitle
,
0
);
assertTypicalCue2
(
subtitle
,
2
);
assertThat
(
subtitle
.
getEventTime
(
2
)).
isEqualTo
(
2_000_000
);
assertThat
(
subtitle
.
getEventTime
(
3
)).
isEqualTo
(
3_000_000
);
assertTypicalCue3
(
subtitle
,
4
);
}
...
...
testdata/src/test/assets/subrip/typical_no_hours
→
testdata/src/test/assets/subrip/typical_no_hours
_and_millis
View file @
2842eb3e
...
...
@@ -3,7 +3,7 @@
This is the first subtitle.
2
00:0
2,345 --> 00:03,456
00:0
0:02 --> 00:00:03
This is the second subtitle.
Second subtitle with second line.
...
...
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