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
25b453a5
authored
May 17, 2021
by
samrobinson
Committed by
Oliver Woodman
May 19, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add track number & total to MediaMetadata
#minor-release PiperOrigin-RevId: 374235979
parent
6fd20dda
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
8 deletions
library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java
library/common/src/main/java/com/google/android/exoplayer2/metadata/id3/TextInformationFrame.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 @
25b453a5
...
@@ -49,6 +49,8 @@ public final class MediaMetadata implements Bundleable {
...
@@ -49,6 +49,8 @@ public final class MediaMetadata implements Bundleable {
@Nullable
private
Rating
overallRating
;
@Nullable
private
Rating
overallRating
;
@Nullable
private
byte
[]
artworkData
;
@Nullable
private
byte
[]
artworkData
;
@Nullable
private
Uri
artworkUri
;
@Nullable
private
Uri
artworkUri
;
@Nullable
private
Integer
trackNumber
;
@Nullable
private
Integer
totalTrackCount
;
public
Builder
()
{}
public
Builder
()
{}
...
@@ -65,6 +67,8 @@ public final class MediaMetadata implements Bundleable {
...
@@ -65,6 +67,8 @@ public final class MediaMetadata implements Bundleable {
this
.
overallRating
=
mediaMetadata
.
overallRating
;
this
.
overallRating
=
mediaMetadata
.
overallRating
;
this
.
artworkData
=
mediaMetadata
.
artworkData
;
this
.
artworkData
=
mediaMetadata
.
artworkData
;
this
.
artworkUri
=
mediaMetadata
.
artworkUri
;
this
.
artworkUri
=
mediaMetadata
.
artworkUri
;
this
.
trackNumber
=
mediaMetadata
.
trackNumber
;
this
.
totalTrackCount
=
mediaMetadata
.
totalTrackCount
;
}
}
/** Sets the title. */
/** Sets the title. */
...
@@ -143,6 +147,18 @@ public final class MediaMetadata implements Bundleable {
...
@@ -143,6 +147,18 @@ public final class MediaMetadata implements Bundleable {
return
this
;
return
this
;
}
}
/** Sets the track number. */
public
Builder
setTrackNumber
(
@Nullable
Integer
trackNumber
)
{
this
.
trackNumber
=
trackNumber
;
return
this
;
}
/** Sets the total number of tracks. */
public
Builder
setTotalTrackCount
(
@Nullable
Integer
totalTrackCount
)
{
this
.
totalTrackCount
=
totalTrackCount
;
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}.
*
*
...
@@ -218,6 +234,10 @@ public final class MediaMetadata implements Bundleable {
...
@@ -218,6 +234,10 @@ public final class MediaMetadata implements Bundleable {
@Nullable
public
final
byte
[]
artworkData
;
@Nullable
public
final
byte
[]
artworkData
;
/** Optional artwork {@link Uri}. */
/** Optional artwork {@link Uri}. */
@Nullable
public
final
Uri
artworkUri
;
@Nullable
public
final
Uri
artworkUri
;
/** Optional track number. */
@Nullable
public
final
Integer
trackNumber
;
/** Optional total number of tracks. */
@Nullable
public
final
Integer
totalTrackCount
;
private
MediaMetadata
(
Builder
builder
)
{
private
MediaMetadata
(
Builder
builder
)
{
this
.
title
=
builder
.
title
;
this
.
title
=
builder
.
title
;
...
@@ -232,6 +252,8 @@ public final class MediaMetadata implements Bundleable {
...
@@ -232,6 +252,8 @@ public final class MediaMetadata implements Bundleable {
this
.
overallRating
=
builder
.
overallRating
;
this
.
overallRating
=
builder
.
overallRating
;
this
.
artworkData
=
builder
.
artworkData
;
this
.
artworkData
=
builder
.
artworkData
;
this
.
artworkUri
=
builder
.
artworkUri
;
this
.
artworkUri
=
builder
.
artworkUri
;
this
.
trackNumber
=
builder
.
trackNumber
;
this
.
totalTrackCount
=
builder
.
totalTrackCount
;
}
}
/** Returns a new {@link Builder} instance with the current {@link MediaMetadata} fields. */
/** Returns a new {@link Builder} instance with the current {@link MediaMetadata} fields. */
...
@@ -259,7 +281,9 @@ public final class MediaMetadata implements Bundleable {
...
@@ -259,7 +281,9 @@ public final class MediaMetadata implements Bundleable {
&&
Util
.
areEqual
(
userRating
,
that
.
userRating
)
&&
Util
.
areEqual
(
userRating
,
that
.
userRating
)
&&
Util
.
areEqual
(
overallRating
,
that
.
overallRating
)
&&
Util
.
areEqual
(
overallRating
,
that
.
overallRating
)
&&
Arrays
.
equals
(
artworkData
,
that
.
artworkData
)
&&
Arrays
.
equals
(
artworkData
,
that
.
artworkData
)
&&
Util
.
areEqual
(
artworkUri
,
that
.
artworkUri
);
&&
Util
.
areEqual
(
artworkUri
,
that
.
artworkUri
)
&&
Util
.
areEqual
(
trackNumber
,
that
.
trackNumber
)
&&
Util
.
areEqual
(
totalTrackCount
,
that
.
totalTrackCount
);
}
}
@Override
@Override
...
@@ -276,7 +300,9 @@ public final class MediaMetadata implements Bundleable {
...
@@ -276,7 +300,9 @@ public final class MediaMetadata implements Bundleable {
userRating
,
userRating
,
overallRating
,
overallRating
,
Arrays
.
hashCode
(
artworkData
),
Arrays
.
hashCode
(
artworkData
),
artworkUri
);
artworkUri
,
trackNumber
,
totalTrackCount
);
}
}
// Bundleable implementation.
// Bundleable implementation.
...
@@ -295,7 +321,9 @@ public final class MediaMetadata implements Bundleable {
...
@@ -295,7 +321,9 @@ public final class MediaMetadata implements Bundleable {
FIELD_USER_RATING
,
FIELD_USER_RATING
,
FIELD_OVERALL_RATING
,
FIELD_OVERALL_RATING
,
FIELD_ARTWORK_DATA
,
FIELD_ARTWORK_DATA
,
FIELD_ARTWORK_URI
FIELD_ARTWORK_URI
,
FIELD_TRACK_NUMBER
,
FIELD_TOTAL_TRACK_COUNT
})
})
private
@interface
FieldNumber
{}
private
@interface
FieldNumber
{}
...
@@ -311,6 +339,8 @@ public final class MediaMetadata implements Bundleable {
...
@@ -311,6 +339,8 @@ public final class MediaMetadata implements Bundleable {
private
static
final
int
FIELD_OVERALL_RATING
=
9
;
private
static
final
int
FIELD_OVERALL_RATING
=
9
;
private
static
final
int
FIELD_ARTWORK_DATA
=
10
;
private
static
final
int
FIELD_ARTWORK_DATA
=
10
;
private
static
final
int
FIELD_ARTWORK_URI
=
11
;
private
static
final
int
FIELD_ARTWORK_URI
=
11
;
private
static
final
int
FIELD_TRACK_NUMBER
=
12
;
private
static
final
int
FIELD_TOTAL_TRACK_COUNT
=
13
;
@Override
@Override
public
Bundle
toBundle
()
{
public
Bundle
toBundle
()
{
...
@@ -332,7 +362,12 @@ public final class MediaMetadata implements Bundleable {
...
@@ -332,7 +362,12 @@ public final class MediaMetadata implements Bundleable {
if
(
overallRating
!=
null
)
{
if
(
overallRating
!=
null
)
{
bundle
.
putBundle
(
keyForField
(
FIELD_OVERALL_RATING
),
overallRating
.
toBundle
());
bundle
.
putBundle
(
keyForField
(
FIELD_OVERALL_RATING
),
overallRating
.
toBundle
());
}
}
if
(
trackNumber
!=
null
)
{
bundle
.
putInt
(
keyForField
(
FIELD_TRACK_NUMBER
),
trackNumber
);
}
if
(
totalTrackCount
!=
null
)
{
bundle
.
putInt
(
keyForField
(
FIELD_TOTAL_TRACK_COUNT
),
totalTrackCount
);
}
return
bundle
;
return
bundle
;
}
}
...
@@ -365,6 +400,12 @@ public final class MediaMetadata implements Bundleable {
...
@@ -365,6 +400,12 @@ public final class MediaMetadata implements Bundleable {
builder
.
setOverallRating
(
Rating
.
CREATOR
.
fromBundle
(
fieldBundle
));
builder
.
setOverallRating
(
Rating
.
CREATOR
.
fromBundle
(
fieldBundle
));
}
}
}
}
if
(
bundle
.
containsKey
(
keyForField
(
FIELD_TRACK_NUMBER
)))
{
builder
.
setTrackNumber
(
bundle
.
getInt
(
keyForField
(
FIELD_TRACK_NUMBER
)));
}
if
(
bundle
.
containsKey
(
keyForField
(
FIELD_TOTAL_TRACK_COUNT
)))
{
builder
.
setTotalTrackCount
(
bundle
.
getInt
(
keyForField
(
FIELD_TOTAL_TRACK_COUNT
)));
}
return
builder
.
build
();
return
builder
.
build
();
}
}
...
...
library/common/src/main/java/com/google/android/exoplayer2/metadata/id3/TextInformationFrame.java
View file @
25b453a5
...
@@ -60,6 +60,19 @@ public final class TextInformationFrame extends Id3Frame {
...
@@ -60,6 +60,19 @@ public final class TextInformationFrame extends Id3Frame {
case
"TALB"
:
case
"TALB"
:
builder
.
setAlbumTitle
(
value
);
builder
.
setAlbumTitle
(
value
);
break
;
break
;
case
"TRK"
:
case
"TRCK"
:
String
[]
trackNumbers
=
Util
.
split
(
value
,
"/"
);
try
{
int
trackNumber
=
Integer
.
parseInt
(
trackNumbers
[
0
]);
@Nullable
Integer
totalTrackCount
=
trackNumbers
.
length
>
1
?
Integer
.
parseInt
(
trackNumbers
[
1
])
:
null
;
builder
.
setTrackNumber
(
trackNumber
).
setTotalTrackCount
(
totalTrackCount
);
}
catch
(
NumberFormatException
e
)
{
// Do nothing, invalid input.
}
break
;
default
:
default
:
break
;
break
;
}
}
...
...
library/common/src/test/java/com/google/android/exoplayer2/MediaMetadataTest.java
View file @
25b453a5
...
@@ -23,7 +23,9 @@ import com.google.android.exoplayer2.metadata.Metadata;
...
@@ -23,7 +23,9 @@ import com.google.android.exoplayer2.metadata.Metadata;
import
com.google.android.exoplayer2.metadata.id3.ApicFrame
;
import
com.google.android.exoplayer2.metadata.id3.ApicFrame
;
import
com.google.android.exoplayer2.metadata.id3.TextInformationFrame
;
import
com.google.android.exoplayer2.metadata.id3.TextInformationFrame
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.common.collect.ImmutableList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
...
@@ -91,14 +93,35 @@ public class MediaMetadataTest {
...
@@ -91,14 +93,35 @@ public class MediaMetadataTest {
}
}
@Test
@Test
public
void
builderPopulatedFromTextInformationFrameEntry_sets
Title
()
{
public
void
builderPopulatedFromTextInformationFrameEntry_sets
Values
()
{
String
title
=
"the title"
;
String
title
=
"the title"
;
Metadata
.
Entry
entry
=
String
artist
=
"artist"
;
new
TextInformationFrame
(
/* id= */
"TT2"
,
/* description= */
null
,
/* value= */
title
);
String
albumTitle
=
"album title"
;
String
albumArtist
=
"album Artist"
;
String
trackNumberInfo
=
"11/17"
;
List
<
Metadata
.
Entry
>
entries
=
ImmutableList
.
of
(
new
TextInformationFrame
(
/* id= */
"TT2"
,
/* description= */
null
,
/* value= */
title
),
new
TextInformationFrame
(
/* id= */
"TP1"
,
/* description= */
null
,
/* value= */
artist
),
new
TextInformationFrame
(
/* id= */
"TAL"
,
/* description= */
null
,
/* value= */
albumTitle
),
new
TextInformationFrame
(
/* id= */
"TP2"
,
/* description= */
null
,
/* value= */
albumArtist
),
new
TextInformationFrame
(
/* id= */
"TRK"
,
/* description= */
null
,
/* value= */
trackNumberInfo
));
MediaMetadata
.
Builder
builder
=
MediaMetadata
.
EMPTY
.
buildUpon
();
MediaMetadata
.
Builder
builder
=
MediaMetadata
.
EMPTY
.
buildUpon
();
entry
.
populateMediaMetadata
(
builder
);
for
(
Metadata
.
Entry
entry
:
entries
)
{
entry
.
populateMediaMetadata
(
builder
);
}
assertThat
(
builder
.
build
().
title
.
toString
()).
isEqualTo
(
title
);
assertThat
(
builder
.
build
().
title
.
toString
()).
isEqualTo
(
title
);
assertThat
(
builder
.
build
().
artist
.
toString
()).
isEqualTo
(
artist
);
assertThat
(
builder
.
build
().
albumTitle
.
toString
()).
isEqualTo
(
albumTitle
);
assertThat
(
builder
.
build
().
albumArtist
.
toString
()).
isEqualTo
(
albumArtist
);
assertThat
(
builder
.
build
().
trackNumber
).
isEqualTo
(
11
);
assertThat
(
builder
.
build
().
totalTrackCount
).
isEqualTo
(
17
);
}
}
@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