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
fefa6cb8
authored
Sep 22, 2021
by
ibaker
Committed by
bachinger
Sep 23, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add MediaItem.Subtitle.Builder
PiperOrigin-RevId: 398200055
parent
a194d73c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
41 deletions
library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java
library/common/src/test/java/com/google/android/exoplayer2/MediaItemTest.java
library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java
View file @
fefa6cb8
...
...
@@ -1187,6 +1187,75 @@ public final class MediaItem implements Bundleable {
/** Properties for a text track. */
public
static
final
class
Subtitle
{
/** Builder for {@link Subtitle} instances. */
public
static
final
class
Builder
{
private
Uri
uri
;
@Nullable
private
String
mimeType
;
@Nullable
private
String
language
;
@C
.
SelectionFlags
private
int
selectionFlags
;
@C
.
RoleFlags
private
int
roleFlags
;
@Nullable
private
String
label
;
/**
* Constructs an instance.
*
* @param uri The {@link Uri} to the subtitle file.
*/
public
Builder
(
Uri
uri
)
{
this
.
uri
=
uri
;
}
private
Builder
(
Subtitle
subtitle
)
{
this
.
uri
=
subtitle
.
uri
;
this
.
mimeType
=
subtitle
.
mimeType
;
this
.
language
=
subtitle
.
language
;
this
.
selectionFlags
=
subtitle
.
selectionFlags
;
this
.
roleFlags
=
subtitle
.
roleFlags
;
this
.
label
=
subtitle
.
label
;
}
/** Sets the {@link Uri} to the subtitle file. */
public
Builder
setUri
(
Uri
uri
)
{
this
.
uri
=
uri
;
return
this
;
}
/** Sets the MIME type. */
public
Builder
setMimeType
(
String
mimeType
)
{
this
.
mimeType
=
mimeType
;
return
this
;
}
/** Sets the optional language of the subtitle file. */
public
Builder
setLanguage
(
@Nullable
String
language
)
{
this
.
language
=
language
;
return
this
;
}
/** Sets the flags used for track selection. */
public
Builder
setSelectionFlags
(
@C
.
SelectionFlags
int
selectionFlags
)
{
this
.
selectionFlags
=
selectionFlags
;
return
this
;
}
/** Sets the role flags. These are used for track selection. */
public
Builder
setRoleFlags
(
@C
.
RoleFlags
int
roleFlags
)
{
this
.
roleFlags
=
roleFlags
;
return
this
;
}
/** Sets the optional label for this subtitle track. */
public
Builder
setLabel
(
@Nullable
String
label
)
{
this
.
label
=
label
;
return
this
;
}
/** Creates a {@link Subtitle} from the values of this builder. */
public
Subtitle
build
()
{
return
new
Subtitle
(
this
);
}
}
/** The {@link Uri} to the subtitle file. */
public
final
Uri
uri
;
/** The optional MIME type of the subtitle file, or {@code null} if unspecified. */
...
...
@@ -1200,40 +1269,21 @@ public final class MediaItem implements Bundleable {
/** The label. */
@Nullable
public
final
String
label
;
/**
* Creates an instance.
*
* @param uri The {@link Uri URI} to the subtitle file.
* @param mimeType The MIME type.
* @param language The optional language.
*/
/** @deprecated Use {@link Builder} instead. */
@Deprecated
public
Subtitle
(
Uri
uri
,
String
mimeType
,
@Nullable
String
language
)
{
this
(
uri
,
mimeType
,
language
,
/* selectionFlags= */
0
);
}
/**
* Creates an instance.
*
* @param uri The {@link Uri URI} to the subtitle file.
* @param mimeType The MIME type.
* @param language The optional language.
* @param selectionFlags The selection flags.
*/
/** @deprecated Use {@link Builder} instead. */
@Deprecated
public
Subtitle
(
Uri
uri
,
String
mimeType
,
@Nullable
String
language
,
@C
.
SelectionFlags
int
selectionFlags
)
{
this
(
uri
,
mimeType
,
language
,
selectionFlags
,
/* roleFlags= */
0
,
/* label= */
null
);
}
/**
* Creates an instance.
*
* @param uri The {@link Uri URI} to the subtitle file.
* @param mimeType The MIME type.
* @param language The optional language.
* @param selectionFlags The selection flags.
* @param roleFlags The role flags.
* @param label The optional label.
*/
/** @deprecated Use {@link Builder} instead. */
@Deprecated
public
Subtitle
(
Uri
uri
,
String
mimeType
,
...
...
@@ -1249,6 +1299,20 @@ public final class MediaItem implements Bundleable {
this
.
label
=
label
;
}
private
Subtitle
(
Builder
builder
)
{
this
.
uri
=
builder
.
uri
;
this
.
mimeType
=
builder
.
mimeType
;
this
.
language
=
builder
.
language
;
this
.
selectionFlags
=
builder
.
selectionFlags
;
this
.
roleFlags
=
builder
.
roleFlags
;
this
.
label
=
builder
.
label
;
}
/** Returns a {@link Builder} initialized with the values of this instance. */
public
Builder
buildUpon
()
{
return
new
Builder
(
this
);
}
@Override
public
boolean
equals
(
@Nullable
Object
obj
)
{
if
(
this
==
obj
)
{
...
...
library/common/src/test/java/com/google/android/exoplayer2/MediaItemTest.java
View file @
fefa6cb8
...
...
@@ -258,9 +258,17 @@ public class MediaItemTest {
}
@Test
@SuppressWarnings
(
"deprecation"
)
// Using deprecated constructors
public
void
builderSetSubtitles_setsSubtitles
()
{
List
<
MediaItem
.
Subtitle
>
subtitles
=
Arrays
.
asList
(
ImmutableList
.
of
(
new
MediaItem
.
Subtitle
.
Builder
(
Uri
.
parse
(
URI_STRING
+
"/es"
))
.
setMimeType
(
MimeTypes
.
TEXT_SSA
)
.
setLanguage
(
/* language= */
"es"
)
.
setSelectionFlags
(
C
.
SELECTION_FLAG_FORCED
)
.
setRoleFlags
(
C
.
ROLE_FLAG_ALTERNATE
)
.
setLabel
(
"label"
)
.
build
(),
new
MediaItem
.
Subtitle
(
Uri
.
parse
(
URI_STRING
+
"/en"
),
MimeTypes
.
APPLICATION_TTML
,
/* language= */
"en"
),
new
MediaItem
.
Subtitle
(
...
...
@@ -531,14 +539,14 @@ public class MediaItemTest {
.
setLiveMinOffsetMs
(
2222
)
.
setLiveMaxOffsetMs
(
4444
)
.
setSubtitles
(
Collections
.
singletonList
(
new
MediaItem
.
Subtitle
(
Uri
.
parse
(
URI_STRING
+
"/en"
),
MimeTypes
.
APPLICATION_TTML
,
/* language= */
"en"
,
C
.
SELECTION_FLAG_FORCED
,
C
.
ROLE_FLAG_ALTERNATE
,
"label"
)))
ImmutableList
.
of
(
new
MediaItem
.
Subtitle
.
Builder
(
Uri
.
parse
(
URI_STRING
+
"/en"
))
.
setMimeType
(
MimeTypes
.
APPLICATION_TTML
)
.
setLanguage
(
"en"
)
.
setSelectionFlags
(
C
.
SELECTION_FLAG_FORCED
)
.
setRoleFlags
(
C
.
ROLE_FLAG_ALTERNATE
)
.
setLabel
(
"label"
)
.
build
(
)))
.
setTag
(
new
Object
())
.
build
();
...
...
@@ -584,13 +592,13 @@ public class MediaItemTest {
.
build
())
.
setSubtitles
(
ImmutableList
.
of
(
new
MediaItem
.
Subtitle
(
Uri
.
parse
(
URI_STRING
+
"/en"
),
MimeTypes
.
APPLICATION_TTML
,
/* language= */
"en"
,
C
.
SELECTION_FLAG_FORCED
,
C
.
ROLE_FLAG_ALTERNATE
,
"label"
)))
new
MediaItem
.
Subtitle
.
Builder
(
Uri
.
parse
(
URI_STRING
+
"/en"
))
.
setMimeType
(
MimeTypes
.
APPLICATION_TTML
)
.
setLanguage
(
"en"
)
.
setSelectionFlags
(
C
.
SELECTION_FLAG_FORCED
)
.
setRoleFlags
(
C
.
ROLE_FLAG_ALTERNATE
)
.
setLabel
(
"label"
)
.
build
(
)))
.
setTag
(
new
Object
())
.
build
();
...
...
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