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
1b1769bb
authored
Jun 10, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Further simplify SRT support
parent
fbbf3f27
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
62 deletions
library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java
library/src/main/java/com/google/android/exoplayer/text/subrip/SubripCue.java
library/src/main/java/com/google/android/exoplayer/text/subrip/SubripParser.java
library/src/main/java/com/google/android/exoplayer/text/subrip/SubripSubtitle.java
library/src/main/java/com/google/android/exoplayer/util/Util.java
library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java
View file @
1b1769bb
...
@@ -132,7 +132,7 @@ public final class VideoFormatSelectorUtil {
...
@@ -132,7 +132,7 @@ public final class VideoFormatSelectorUtil {
}
}
}
}
return
Util
.
toArray
(
selectedIndexList
);
return
Util
.
to
Int
Array
(
selectedIndexList
);
}
}
/**
/**
...
...
library/src/main/java/com/google/android/exoplayer/text/subrip/SubripCue.java
deleted
100644 → 0
View file @
fbbf3f27
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer
.
text
.
subrip
;
import
com.google.android.exoplayer.text.Cue
;
/**
* A representation of a SubRip cue.
*/
/* package */
final
class
SubripCue
extends
Cue
{
public
final
long
startTime
;
public
final
long
endTime
;
public
SubripCue
(
long
startTime
,
long
endTime
,
CharSequence
text
)
{
super
(
text
);
this
.
startTime
=
startTime
;
this
.
endTime
=
endTime
;
}
}
library/src/main/java/com/google/android/exoplayer/text/subrip/SubripParser.java
View file @
1b1769bb
...
@@ -17,8 +17,10 @@ package com.google.android.exoplayer.text.subrip;
...
@@ -17,8 +17,10 @@ package com.google.android.exoplayer.text.subrip;
import
com.google.android.exoplayer.C
;
import
com.google.android.exoplayer.C
;
import
com.google.android.exoplayer.ParserException
;
import
com.google.android.exoplayer.ParserException
;
import
com.google.android.exoplayer.text.Cue
;
import
com.google.android.exoplayer.text.SubtitleParser
;
import
com.google.android.exoplayer.text.SubtitleParser
;
import
com.google.android.exoplayer.util.MimeTypes
;
import
com.google.android.exoplayer.util.MimeTypes
;
import
com.google.android.exoplayer.util.Util
;
import
android.text.Html
;
import
android.text.Html
;
import
android.text.Spanned
;
import
android.text.Spanned
;
...
@@ -52,7 +54,8 @@ public final class SubripParser implements SubtitleParser {
...
@@ -52,7 +54,8 @@ public final class SubripParser implements SubtitleParser {
@Override
@Override
public
SubripSubtitle
parse
(
InputStream
inputStream
,
String
inputEncoding
,
long
startTimeUs
)
public
SubripSubtitle
parse
(
InputStream
inputStream
,
String
inputEncoding
,
long
startTimeUs
)
throws
IOException
{
throws
IOException
{
ArrayList
<
SubripCue
>
cues
=
new
ArrayList
<>();
ArrayList
<
Cue
>
cues
=
new
ArrayList
<>();
ArrayList
<
Long
>
cueTimesUs
=
new
ArrayList
<>();
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
C
.
UTF8_NAME
));
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
C
.
UTF8_NAME
));
String
currentLine
;
String
currentLine
;
...
@@ -65,13 +68,11 @@ public final class SubripParser implements SubtitleParser {
...
@@ -65,13 +68,11 @@ public final class SubripParser implements SubtitleParser {
}
}
// Read and parse the timing line.
// Read and parse the timing line.
long
cueStartTimeUs
;
long
cueEndTimeUs
;
currentLine
=
reader
.
readLine
();
currentLine
=
reader
.
readLine
();
Matcher
matcher
=
SUBRIP_TIMING_LINE
.
matcher
(
currentLine
);
Matcher
matcher
=
SUBRIP_TIMING_LINE
.
matcher
(
currentLine
);
if
(
matcher
.
find
())
{
if
(
matcher
.
find
())
{
cue
StartTimeUs
=
parseTimestampUs
(
matcher
.
group
(
1
))
+
startTimeUs
;
cue
TimesUs
.
add
(
startTimeUs
+
parseTimestampUs
(
matcher
.
group
(
1
)))
;
cue
EndTimeUs
=
parseTimestampUs
(
matcher
.
group
(
2
))
+
startTimeUs
;
cue
TimesUs
.
add
(
startTimeUs
+
parseTimestampUs
(
matcher
.
group
(
2
)))
;
}
else
{
}
else
{
throw
new
ParserException
(
"Expected timing line: "
+
currentLine
);
throw
new
ParserException
(
"Expected timing line: "
+
currentLine
);
}
}
...
@@ -86,14 +87,16 @@ public final class SubripParser implements SubtitleParser {
...
@@ -86,14 +87,16 @@ public final class SubripParser implements SubtitleParser {
}
}
Spanned
text
=
Html
.
fromHtml
(
textBuilder
.
toString
());
Spanned
text
=
Html
.
fromHtml
(
textBuilder
.
toString
());
SubripCue
cue
=
new
SubripCue
(
cueStartTimeUs
,
cueEndTimeUs
,
text
);
cues
.
add
(
new
Cue
(
text
));
cues
.
add
(
cue
);
}
}
reader
.
close
();
reader
.
close
();
inputStream
.
close
();
inputStream
.
close
();
SubripSubtitle
subtitle
=
new
SubripSubtitle
(
cues
,
startTimeUs
);
return
subtitle
;
Cue
[]
cuesArray
=
new
Cue
[
cues
.
size
()];
cues
.
toArray
(
cuesArray
);
long
[]
cueTimesUsArray
=
Util
.
toLongArray
(
cueTimesUs
);
return
new
SubripSubtitle
(
startTimeUs
,
cuesArray
,
cueTimesUsArray
);
}
}
@Override
@Override
...
...
library/src/main/java/com/google/android/exoplayer/text/subrip/SubripSubtitle.java
View file @
1b1769bb
...
@@ -28,27 +28,20 @@ import java.util.List;
...
@@ -28,27 +28,20 @@ import java.util.List;
*/
*/
/* package */
final
class
SubripSubtitle
implements
Subtitle
{
/* package */
final
class
SubripSubtitle
implements
Subtitle
{
private
final
List
<
SubripCue
>
cues
;
private
final
int
numCues
;
private
final
long
startTimeUs
;
private
final
long
startTimeUs
;
private
final
Cue
[]
cues
;
private
final
long
[]
cueTimesUs
;
private
final
long
[]
cueTimesUs
;
/**
/**
* @param cues A list of the cues in this subtitle.
* @param startTimeUs The start time of the subtitle, in microseconds.
* @param startTimeUs The start time of the subtitle.
* @param cues The cues in the subtitle.
* @param cueTimesUs Interleaved cue start and end times, in microseconds.
*/
*/
public
SubripSubtitle
(
List
<
SubripCue
>
cues
,
long
startTimeUs
)
{
public
SubripSubtitle
(
long
startTimeUs
,
Cue
[]
cues
,
long
[]
cueTimesUs
)
{
this
.
cues
=
cues
;
this
.
startTimeUs
=
startTimeUs
;
this
.
startTimeUs
=
startTimeUs
;
this
.
cues
=
cues
;
numCues
=
cues
.
size
();
this
.
cueTimesUs
=
cueTimesUs
;
cueTimesUs
=
new
long
[
2
*
numCues
];
for
(
int
cueIndex
=
0
;
cueIndex
<
numCues
;
cueIndex
++)
{
SubripCue
cue
=
cues
.
get
(
cueIndex
);
int
arrayIndex
=
cueIndex
*
2
;
cueTimesUs
[
arrayIndex
]
=
cue
.
startTime
;
cueTimesUs
[
arrayIndex
+
1
]
=
cue
.
endTime
;
}
}
}
@Override
@Override
...
@@ -58,7 +51,6 @@ import java.util.List;
...
@@ -58,7 +51,6 @@ import java.util.List;
@Override
@Override
public
int
getNextEventTimeIndex
(
long
timeUs
)
{
public
int
getNextEventTimeIndex
(
long
timeUs
)
{
Assertions
.
checkArgument
(
timeUs
>=
0
);
int
index
=
Util
.
binarySearchCeil
(
cueTimesUs
,
timeUs
,
false
,
false
);
int
index
=
Util
.
binarySearchCeil
(
cueTimesUs
,
timeUs
,
false
,
false
);
return
index
<
cueTimesUs
.
length
?
index
:
-
1
;
return
index
<
cueTimesUs
.
length
?
index
:
-
1
;
}
}
...
@@ -90,7 +82,7 @@ import java.util.List;
...
@@ -90,7 +82,7 @@ import java.util.List;
// timeUs is earlier than the start of the first cue, or corresponds to a gap between cues.
// timeUs is earlier than the start of the first cue, or corresponds to a gap between cues.
return
Collections
.<
Cue
>
emptyList
();
return
Collections
.<
Cue
>
emptyList
();
}
else
{
}
else
{
return
Collections
.
singletonList
(
(
Cue
)
cues
.
get
(
index
/
2
)
);
return
Collections
.
singletonList
(
cues
[
index
/
2
]
);
}
}
}
}
...
...
library/src/main/java/com/google/android/exoplayer/util/Util.java
View file @
1b1769bb
...
@@ -459,7 +459,7 @@ public final class Util {
...
@@ -459,7 +459,7 @@ public final class Util {
* @param list A list of integers.
* @param list A list of integers.
* @return The list in array form, or null if the input list was null.
* @return The list in array form, or null if the input list was null.
*/
*/
public
static
int
[]
toArray
(
List
<
Integer
>
list
)
{
public
static
int
[]
to
Int
Array
(
List
<
Integer
>
list
)
{
if
(
list
==
null
)
{
if
(
list
==
null
)
{
return
null
;
return
null
;
}
}
...
@@ -472,6 +472,24 @@ public final class Util {
...
@@ -472,6 +472,24 @@ public final class Util {
}
}
/**
/**
* Converts a list of longs to a primitive array.
*
* @param list A list of longs.
* @return The list in array form, or null if the input list was null.
*/
public
static
long
[]
toLongArray
(
List
<
Long
>
list
)
{
if
(
list
==
null
)
{
return
null
;
}
int
length
=
list
.
size
();
long
[]
longArray
=
new
long
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
longArray
[
i
]
=
list
.
get
(
i
);
}
return
longArray
;
}
/**
* On platform API levels 19 and 20, okhttp's implementation of {@link InputStream#close} can
* On platform API levels 19 and 20, okhttp's implementation of {@link InputStream#close} can
* block for a long time if the stream has a lot of data remaining. Call this method before
* block for a long time if the stream has a lot of data remaining. Call this method before
* closing the input stream to make a best effort to cause the input stream to encounter an
* closing the input stream to make a best effort to cause the input stream to encounter an
...
...
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