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
cc26a92e
authored
Apr 13, 2021
by
bachinger
Committed by
Andrew Lewis
Apr 13, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use MediaItem.DEFAULT_MEDIA_ID as default media ID
PiperOrigin-RevId: 368204261
parent
1d3f72c9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
19 deletions
RELEASENOTES.md
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/DefaultMediaItemConverter.java
library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java
library/common/src/test/java/com/google/android/exoplayer2/MediaItemTest.java
RELEASENOTES.md
View file @
cc26a92e
...
@@ -74,6 +74,8 @@
...
@@ -74,6 +74,8 @@
*
Assume Dolby Vision content is encoded as H264 when calculating maximum
*
Assume Dolby Vision content is encoded as H264 when calculating maximum
codec input size
codec input size
(
[
#8705
](
https://github.com/google/ExoPlayer/issues/8705
)
).
(
[
#8705
](
https://github.com/google/ExoPlayer/issues/8705
)
).
*
Use an empty string instead of the URI if the media ID is not explicitly
set with
`MediaItem.Builder.setMediaId(String)`
.
*
HLS:
*
HLS:
*
Fix bug of ignoring
`EXT-X-START`
when setting the live target offset
*
Fix bug of ignoring
`EXT-X-START`
when setting the live target offset
(
[
#8764
](
https://github.com/google/ExoPlayer/pull/8764
)
).
(
[
#8764
](
https://github.com/google/ExoPlayer/pull/8764
)
).
...
...
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/DefaultMediaItemConverter.java
View file @
cc26a92e
...
@@ -84,7 +84,7 @@ public class DefaultMediaItemConverter implements MediaItemConverter {
...
@@ -84,7 +84,7 @@ public class DefaultMediaItemConverter implements MediaItemConverter {
return
new
MediaItem
.
Builder
()
return
new
MediaItem
.
Builder
()
.
setUri
(
uri
)
.
setUri
(
uri
)
.
setMediaId
(
mediaId
)
.
setMediaId
(
mediaId
!=
null
?
mediaId
:
MediaItem
.
DEFAULT_MEDIA_ID
)
.
setMediaMetadata
(
.
setMediaMetadata
(
new
com
.
google
.
android
.
exoplayer2
.
MediaMetadata
.
Builder
().
setTitle
(
title
).
build
())
new
com
.
google
.
android
.
exoplayer2
.
MediaMetadata
.
Builder
().
setTitle
(
title
).
build
())
.
setTag
(
media2MediaItem
)
.
setTag
(
media2MediaItem
)
...
...
library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java
View file @
cc26a92e
...
@@ -147,17 +147,17 @@ public final class MediaItem implements Bundleable {
...
@@ -147,17 +147,17 @@ public final class MediaItem implements Bundleable {
}
}
/**
/**
* Sets the optional media ID which identifies the media item.
If not specified, {@link #setUri}
* Sets the optional media ID which identifies the media item.
*
must be called and the string representation of {@link PlaybackProperties#uri} is used as the
*
*
media ID
.
*
<p>By default {@link #DEFAULT_MEDIA_ID} is used
.
*/
*/
public
Builder
setMediaId
(
@Nullable
String
mediaId
)
{
public
Builder
setMediaId
(
String
mediaId
)
{
this
.
mediaId
=
mediaId
;
this
.
mediaId
=
checkNotNull
(
mediaId
)
;
return
this
;
return
this
;
}
}
/**
/**
* Sets the optional URI.
If not specified, {@link #setMediaId(String)} must be called.
* Sets the optional URI.
*
*
* <p>If {@code uri} is null or unset no {@link PlaybackProperties} object is created during
* <p>If {@code uri} is null or unset no {@link PlaybackProperties} object is created during
* {@link #build()} and any other {@code Builder} methods that would populate {@link
* {@link #build()} and any other {@code Builder} methods that would populate {@link
...
@@ -168,7 +168,7 @@ public final class MediaItem implements Bundleable {
...
@@ -168,7 +168,7 @@ public final class MediaItem implements Bundleable {
}
}
/**
/**
* Sets the optional URI.
If not specified, {@link #setMediaId(String)} must be called.
* Sets the optional URI.
*
*
* <p>If {@code uri} is null or unset no {@link PlaybackProperties} object is created during
* <p>If {@code uri} is null or unset no {@link PlaybackProperties} object is created during
* {@link #build()} and any other {@code Builder} methods that would populate {@link
* {@link #build()} and any other {@code Builder} methods that would populate {@link
...
@@ -587,10 +587,9 @@ public final class MediaItem implements Bundleable {
...
@@ -587,10 +587,9 @@ public final class MediaItem implements Bundleable {
customCacheKey
,
customCacheKey
,
subtitles
,
subtitles
,
tag
);
tag
);
mediaId
=
mediaId
!=
null
?
mediaId
:
uri
.
toString
();
}
}
return
new
MediaItem
(
return
new
MediaItem
(
checkNotNull
(
mediaId
)
,
mediaId
!=
null
?
mediaId
:
DEFAULT_MEDIA_ID
,
new
ClippingProperties
(
new
ClippingProperties
(
clipStartPositionMs
,
clipStartPositionMs
,
clipEndPositionMs
,
clipEndPositionMs
,
...
@@ -1194,6 +1193,12 @@ public final class MediaItem implements Bundleable {
...
@@ -1194,6 +1193,12 @@ public final class MediaItem implements Bundleable {
}
}
}
}
/**
* The default media ID that is used if the media ID is not explicitly set by {@link
* Builder#setMediaId(String)}.
*/
public
static
final
String
DEFAULT_MEDIA_ID
=
""
;
/** Identifies the media item. */
/** Identifies the media item. */
public
final
String
mediaId
;
public
final
String
mediaId
;
...
@@ -1296,7 +1301,7 @@ public final class MediaItem implements Bundleable {
...
@@ -1296,7 +1301,7 @@ public final class MediaItem implements Bundleable {
public
static
final
Creator
<
MediaItem
>
CREATOR
=
MediaItem:
:
fromBundle
;
public
static
final
Creator
<
MediaItem
>
CREATOR
=
MediaItem:
:
fromBundle
;
private
static
MediaItem
fromBundle
(
Bundle
bundle
)
{
private
static
MediaItem
fromBundle
(
Bundle
bundle
)
{
String
mediaId
=
checkNotNull
(
bundle
.
getString
(
keyForField
(
FIELD_MEDIA_ID
)));
String
mediaId
=
checkNotNull
(
bundle
.
getString
(
keyForField
(
FIELD_MEDIA_ID
)
,
DEFAULT_MEDIA_ID
));
@Nullable
@Nullable
Bundle
liveConfigurationBundle
=
bundle
.
getBundle
(
keyForField
(
FIELD_LIVE_CONFIGURATION
));
Bundle
liveConfigurationBundle
=
bundle
.
getBundle
(
keyForField
(
FIELD_LIVE_CONFIGURATION
));
LiveConfiguration
liveConfiguration
;
LiveConfiguration
liveConfiguration
;
...
...
library/common/src/test/java/com/google/android/exoplayer2/MediaItemTest.java
View file @
cc26a92e
...
@@ -38,18 +38,12 @@ public class MediaItemTest {
...
@@ -38,18 +38,12 @@ public class MediaItemTest {
private
static
final
String
URI_STRING
=
"http://www.google.com"
;
private
static
final
String
URI_STRING
=
"http://www.google.com"
;
@Test
@Test
public
void
builder_needsUriOrMediaId
()
{
assertThrows
(
NullPointerException
.
class
,
()
->
new
MediaItem
.
Builder
().
build
());
}
@Test
public
void
builderWithUri_setsUri
()
{
public
void
builderWithUri_setsUri
()
{
Uri
uri
=
Uri
.
parse
(
URI_STRING
);
Uri
uri
=
Uri
.
parse
(
URI_STRING
);
MediaItem
mediaItem
=
MediaItem
.
fromUri
(
uri
);
MediaItem
mediaItem
=
MediaItem
.
fromUri
(
uri
);
assertThat
(
mediaItem
.
playbackProperties
.
uri
.
toString
()).
isEqualTo
(
URI_STRING
);
assertThat
(
mediaItem
.
playbackProperties
.
uri
).
isEqualTo
(
uri
);
assertThat
(
mediaItem
.
mediaId
).
isEqualTo
(
URI_STRING
);
assertThat
(
mediaItem
.
mediaMetadata
).
isNotNull
();
assertThat
(
mediaItem
.
mediaMetadata
).
isNotNull
();
}
}
...
@@ -58,7 +52,13 @@ public class MediaItemTest {
...
@@ -58,7 +52,13 @@ public class MediaItemTest {
MediaItem
mediaItem
=
MediaItem
.
fromUri
(
URI_STRING
);
MediaItem
mediaItem
=
MediaItem
.
fromUri
(
URI_STRING
);
assertThat
(
mediaItem
.
playbackProperties
.
uri
.
toString
()).
isEqualTo
(
URI_STRING
);
assertThat
(
mediaItem
.
playbackProperties
.
uri
.
toString
()).
isEqualTo
(
URI_STRING
);
assertThat
(
mediaItem
.
mediaId
).
isEqualTo
(
URI_STRING
);
}
@Test
public
void
builderWithoutMediaId_usesDefaultMediaId
()
{
MediaItem
mediaItem
=
MediaItem
.
fromUri
(
URI_STRING
);
assertThat
(
mediaItem
.
mediaId
).
isEqualTo
(
MediaItem
.
DEFAULT_MEDIA_ID
);
}
}
@Test
@Test
...
...
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