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
81b8bb67
authored
May 24, 2021
by
samrobinson
Committed by
Oliver Woodman
Jun 06, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add an extras bundle to MediaMetadata.
#minor-release PiperOrigin-RevId: 375435339
parent
ae400176
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
3 deletions
library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java
library/common/src/test/java/com/google/android/exoplayer2/MediaMetadataTest.java
library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java
View file @
81b8bb67
...
@@ -53,6 +53,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -53,6 +53,7 @@ public final class MediaMetadata implements Bundleable {
@Nullable
private
Integer
totalTrackCount
;
@Nullable
private
Integer
totalTrackCount
;
@Nullable
@FolderType
private
Integer
folderType
;
@Nullable
@FolderType
private
Integer
folderType
;
@Nullable
private
Boolean
isPlayable
;
@Nullable
private
Boolean
isPlayable
;
@Nullable
private
Bundle
extras
;
public
Builder
()
{}
public
Builder
()
{}
...
@@ -73,6 +74,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -73,6 +74,7 @@ public final class MediaMetadata implements Bundleable {
this
.
totalTrackCount
=
mediaMetadata
.
totalTrackCount
;
this
.
totalTrackCount
=
mediaMetadata
.
totalTrackCount
;
this
.
folderType
=
mediaMetadata
.
folderType
;
this
.
folderType
=
mediaMetadata
.
folderType
;
this
.
isPlayable
=
mediaMetadata
.
isPlayable
;
this
.
isPlayable
=
mediaMetadata
.
isPlayable
;
this
.
extras
=
mediaMetadata
.
extras
;
}
}
/** Sets the title. */
/** Sets the title. */
...
@@ -175,6 +177,12 @@ public final class MediaMetadata implements Bundleable {
...
@@ -175,6 +177,12 @@ public final class MediaMetadata implements Bundleable {
return
this
;
return
this
;
}
}
/** Sets the extras {@link Bundle}. */
public
Builder
setExtras
(
@Nullable
Bundle
extras
)
{
this
.
extras
=
extras
;
return
this
;
}
/**
/**
* Sets all fields supported by the {@link Metadata.Entry entries} within the {@link Metadata}.
* Sets all fields supported by the {@link Metadata.Entry entries} within the {@link Metadata}.
*
*
...
@@ -293,6 +301,13 @@ public final class MediaMetadata implements Bundleable {
...
@@ -293,6 +301,13 @@ public final class MediaMetadata implements Bundleable {
@Nullable
@FolderType
public
final
Integer
folderType
;
@Nullable
@FolderType
public
final
Integer
folderType
;
/** Optional boolean for media playability. */
/** Optional boolean for media playability. */
@Nullable
public
final
Boolean
isPlayable
;
@Nullable
public
final
Boolean
isPlayable
;
/**
* Optional extras {@link Bundle}.
*
* <p>Given the complexities of checking the equality of two {@link Bundle}s, this is not
* considered in the {@link #equals(Object)} or {@link #hashCode()}.
*/
@Nullable
public
final
Bundle
extras
;
private
MediaMetadata
(
Builder
builder
)
{
private
MediaMetadata
(
Builder
builder
)
{
this
.
title
=
builder
.
title
;
this
.
title
=
builder
.
title
;
...
@@ -311,6 +326,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -311,6 +326,7 @@ public final class MediaMetadata implements Bundleable {
this
.
totalTrackCount
=
builder
.
totalTrackCount
;
this
.
totalTrackCount
=
builder
.
totalTrackCount
;
this
.
folderType
=
builder
.
folderType
;
this
.
folderType
=
builder
.
folderType
;
this
.
isPlayable
=
builder
.
isPlayable
;
this
.
isPlayable
=
builder
.
isPlayable
;
this
.
extras
=
builder
.
extras
;
}
}
/** Returns a new {@link Builder} instance with the current {@link MediaMetadata} fields. */
/** Returns a new {@link Builder} instance with the current {@link MediaMetadata} fields. */
...
@@ -386,7 +402,8 @@ public final class MediaMetadata implements Bundleable {
...
@@ -386,7 +402,8 @@ public final class MediaMetadata implements Bundleable {
FIELD_TRACK_NUMBER
,
FIELD_TRACK_NUMBER
,
FIELD_TOTAL_TRACK_COUNT
,
FIELD_TOTAL_TRACK_COUNT
,
FIELD_FOLDER_TYPE
,
FIELD_FOLDER_TYPE
,
FIELD_IS_PLAYABLE
FIELD_IS_PLAYABLE
,
FIELD_EXTRAS
})
})
private
@interface
FieldNumber
{}
private
@interface
FieldNumber
{}
...
@@ -406,6 +423,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -406,6 +423,7 @@ public final class MediaMetadata implements Bundleable {
private
static
final
int
FIELD_TOTAL_TRACK_COUNT
=
13
;
private
static
final
int
FIELD_TOTAL_TRACK_COUNT
=
13
;
private
static
final
int
FIELD_FOLDER_TYPE
=
14
;
private
static
final
int
FIELD_FOLDER_TYPE
=
14
;
private
static
final
int
FIELD_IS_PLAYABLE
=
15
;
private
static
final
int
FIELD_IS_PLAYABLE
=
15
;
private
static
final
int
FIELD_EXTRAS
=
1000
;
@Override
@Override
public
Bundle
toBundle
()
{
public
Bundle
toBundle
()
{
...
@@ -439,7 +457,9 @@ public final class MediaMetadata implements Bundleable {
...
@@ -439,7 +457,9 @@ public final class MediaMetadata implements Bundleable {
if
(
isPlayable
!=
null
)
{
if
(
isPlayable
!=
null
)
{
bundle
.
putBoolean
(
keyForField
(
FIELD_IS_PLAYABLE
),
isPlayable
);
bundle
.
putBoolean
(
keyForField
(
FIELD_IS_PLAYABLE
),
isPlayable
);
}
}
if
(
extras
!=
null
)
{
bundle
.
putBundle
(
keyForField
(
FIELD_EXTRAS
),
extras
);
}
return
bundle
;
return
bundle
;
}
}
...
@@ -458,7 +478,8 @@ public final class MediaMetadata implements Bundleable {
...
@@ -458,7 +478,8 @@ public final class MediaMetadata implements Bundleable {
.
setDescription
(
bundle
.
getCharSequence
(
keyForField
(
FIELD_DESCRIPTION
)))
.
setDescription
(
bundle
.
getCharSequence
(
keyForField
(
FIELD_DESCRIPTION
)))
.
setMediaUri
(
bundle
.
getParcelable
(
keyForField
(
FIELD_MEDIA_URI
)))
.
setMediaUri
(
bundle
.
getParcelable
(
keyForField
(
FIELD_MEDIA_URI
)))
.
setArtworkData
(
bundle
.
getByteArray
(
keyForField
(
FIELD_ARTWORK_DATA
)))
.
setArtworkData
(
bundle
.
getByteArray
(
keyForField
(
FIELD_ARTWORK_DATA
)))
.
setArtworkUri
(
bundle
.
getParcelable
(
keyForField
(
FIELD_ARTWORK_URI
)));
.
setArtworkUri
(
bundle
.
getParcelable
(
keyForField
(
FIELD_ARTWORK_URI
)))
.
setExtras
(
bundle
.
getBundle
(
keyForField
(
FIELD_EXTRAS
)));
if
(
bundle
.
containsKey
(
keyForField
(
FIELD_USER_RATING
)))
{
if
(
bundle
.
containsKey
(
keyForField
(
FIELD_USER_RATING
)))
{
@Nullable
Bundle
fieldBundle
=
bundle
.
getBundle
(
keyForField
(
FIELD_USER_RATING
));
@Nullable
Bundle
fieldBundle
=
bundle
.
getBundle
(
keyForField
(
FIELD_USER_RATING
));
...
...
library/common/src/test/java/com/google/android/exoplayer2/MediaMetadataTest.java
View file @
81b8bb67
...
@@ -18,6 +18,7 @@ package com.google.android.exoplayer2;
...
@@ -18,6 +18,7 @@ package com.google.android.exoplayer2;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.metadata.Metadata
;
import
com.google.android.exoplayer2.metadata.Metadata
;
import
com.google.android.exoplayer2.metadata.id3.ApicFrame
;
import
com.google.android.exoplayer2.metadata.id3.ApicFrame
;
...
@@ -49,8 +50,11 @@ public class MediaMetadataTest {
...
@@ -49,8 +50,11 @@ public class MediaMetadataTest {
assertThat
(
mediaMetadata
.
overallRating
).
isNull
();
assertThat
(
mediaMetadata
.
overallRating
).
isNull
();
assertThat
(
mediaMetadata
.
artworkData
).
isNull
();
assertThat
(
mediaMetadata
.
artworkData
).
isNull
();
assertThat
(
mediaMetadata
.
artworkUri
).
isNull
();
assertThat
(
mediaMetadata
.
artworkUri
).
isNull
();
assertThat
(
mediaMetadata
.
trackNumber
).
isNull
();
assertThat
(
mediaMetadata
.
totalTrackCount
).
isNull
();
assertThat
(
mediaMetadata
.
folderType
).
isNull
();
assertThat
(
mediaMetadata
.
folderType
).
isNull
();
assertThat
(
mediaMetadata
.
isPlayable
).
isNull
();
assertThat
(
mediaMetadata
.
isPlayable
).
isNull
();
assertThat
(
mediaMetadata
.
extras
).
isNull
();
}
}
@Test
@Test
...
@@ -80,6 +84,9 @@ public class MediaMetadataTest {
...
@@ -80,6 +84,9 @@ public class MediaMetadataTest {
@Test
@Test
public
void
roundTripViaBundle_yieldsEqualInstance
()
{
public
void
roundTripViaBundle_yieldsEqualInstance
()
{
Bundle
extras
=
new
Bundle
();
extras
.
putString
(
"exampleKey"
,
"exampleValue"
);
MediaMetadata
mediaMetadata
=
MediaMetadata
mediaMetadata
=
new
MediaMetadata
.
Builder
()
new
MediaMetadata
.
Builder
()
.
setTitle
(
"title"
)
.
setTitle
(
"title"
)
...
@@ -88,12 +95,16 @@ public class MediaMetadataTest {
...
@@ -88,12 +95,16 @@ public class MediaMetadataTest {
.
setUserRating
(
new
HeartRating
(
false
))
.
setUserRating
(
new
HeartRating
(
false
))
.
setOverallRating
(
new
PercentageRating
(
87.4f
))
.
setOverallRating
(
new
PercentageRating
(
87.4f
))
.
setArtworkData
(
new
byte
[]
{-
88
,
12
,
3
,
2
,
124
,
-
54
,
-
33
,
69
})
.
setArtworkData
(
new
byte
[]
{-
88
,
12
,
3
,
2
,
124
,
-
54
,
-
33
,
69
})
.
setTrackNumber
(
4
)
.
setTotalTrackCount
(
12
)
.
setFolderType
(
MediaMetadata
.
FOLDER_TYPE_PLAYLISTS
)
.
setFolderType
(
MediaMetadata
.
FOLDER_TYPE_PLAYLISTS
)
.
setIsPlayable
(
true
)
.
setIsPlayable
(
true
)
.
setExtras
(
extras
)
// Extras is not implemented in MediaMetadata.equals(Object o).
.
build
();
.
build
();
MediaMetadata
fromBundle
=
MediaMetadata
.
CREATOR
.
fromBundle
(
mediaMetadata
.
toBundle
());
MediaMetadata
fromBundle
=
MediaMetadata
.
CREATOR
.
fromBundle
(
mediaMetadata
.
toBundle
());
assertThat
(
fromBundle
).
isEqualTo
(
mediaMetadata
);
assertThat
(
fromBundle
).
isEqualTo
(
mediaMetadata
);
assertThat
(
fromBundle
.
extras
.
getString
(
"exampleKey"
)).
isEqualTo
(
"exampleValue"
);
}
}
@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