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
5e9b0c2f
authored
Apr 05, 2023
by
tonihei
Committed by
Ian Baker
Apr 11, 2023
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Deprecate MediaMetadata folderType and stabilize mediaType+isBrowsable
PiperOrigin-RevId: 522058915
parent
2e84360a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
22 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 @
5e9b0c2f
...
@@ -60,7 +60,11 @@ public final class MediaMetadata implements Bundleable {
...
@@ -60,7 +60,11 @@ public final class MediaMetadata implements Bundleable {
@Nullable
private
Uri
artworkUri
;
@Nullable
private
Uri
artworkUri
;
@Nullable
private
Integer
trackNumber
;
@Nullable
private
Integer
trackNumber
;
@Nullable
private
Integer
totalTrackCount
;
@Nullable
private
Integer
totalTrackCount
;
@Nullable
private
@FolderType
Integer
folderType
;
@SuppressWarnings
(
"deprecation"
)
// Builder for deprecated field.
@Nullable
private
@FolderType
Integer
folderType
;
@Nullable
private
Boolean
isBrowsable
;
@Nullable
private
Boolean
isBrowsable
;
@Nullable
private
Boolean
isPlayable
;
@Nullable
private
Boolean
isPlayable
;
@Nullable
private
Integer
recordingYear
;
@Nullable
private
Integer
recordingYear
;
...
@@ -82,6 +86,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -82,6 +86,7 @@ public final class MediaMetadata implements Bundleable {
public
Builder
()
{}
public
Builder
()
{}
@SuppressWarnings
(
"deprecation"
)
// Assigning from deprecated fields.
private
Builder
(
MediaMetadata
mediaMetadata
)
{
private
Builder
(
MediaMetadata
mediaMetadata
)
{
this
.
title
=
mediaMetadata
.
title
;
this
.
title
=
mediaMetadata
.
title
;
this
.
artist
=
mediaMetadata
.
artist
;
this
.
artist
=
mediaMetadata
.
artist
;
...
@@ -250,9 +255,11 @@ public final class MediaMetadata implements Bundleable {
...
@@ -250,9 +255,11 @@ public final class MediaMetadata implements Bundleable {
/**
/**
* Sets the {@link FolderType}.
* Sets the {@link FolderType}.
*
*
*
<p>This method will be deprecated. Use {@link #setIsBrowsable} to indicate if an item is a
*
@deprecated Use {@link #setIsBrowsable} to indicate if an item is a browsable folder and use
*
browsable folder and use
{@link #setMediaType} to indicate the type of the folder.
*
{@link #setMediaType} to indicate the type of the folder.
*/
*/
@SuppressWarnings
(
"deprecation"
)
// Using deprecated type.
@Deprecated
@CanIgnoreReturnValue
@CanIgnoreReturnValue
public
Builder
setFolderType
(
@Nullable
@FolderType
Integer
folderType
)
{
public
Builder
setFolderType
(
@Nullable
@FolderType
Integer
folderType
)
{
this
.
folderType
=
folderType
;
this
.
folderType
=
folderType
;
...
@@ -452,6 +459,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -452,6 +459,7 @@ public final class MediaMetadata implements Bundleable {
}
}
/** Populates all the fields from {@code mediaMetadata}, provided they are non-null. */
/** Populates all the fields from {@code mediaMetadata}, provided they are non-null. */
@SuppressWarnings
(
"deprecation"
)
// Populating deprecated fields.
@CanIgnoreReturnValue
@CanIgnoreReturnValue
public
Builder
populate
(
@Nullable
MediaMetadata
mediaMetadata
)
{
public
Builder
populate
(
@Nullable
MediaMetadata
mediaMetadata
)
{
if
(
mediaMetadata
==
null
)
{
if
(
mediaMetadata
==
null
)
{
...
@@ -745,12 +753,17 @@ public final class MediaMetadata implements Bundleable {
...
@@ -745,12 +753,17 @@ public final class MediaMetadata implements Bundleable {
* <p>One of {@link #FOLDER_TYPE_NONE}, {@link #FOLDER_TYPE_MIXED}, {@link #FOLDER_TYPE_TITLES},
* <p>One of {@link #FOLDER_TYPE_NONE}, {@link #FOLDER_TYPE_MIXED}, {@link #FOLDER_TYPE_TITLES},
* {@link #FOLDER_TYPE_ALBUMS}, {@link #FOLDER_TYPE_ARTISTS}, {@link #FOLDER_TYPE_GENRES}, {@link
* {@link #FOLDER_TYPE_ALBUMS}, {@link #FOLDER_TYPE_ARTISTS}, {@link #FOLDER_TYPE_GENRES}, {@link
* #FOLDER_TYPE_PLAYLISTS} or {@link #FOLDER_TYPE_YEARS}.
* #FOLDER_TYPE_PLAYLISTS} or {@link #FOLDER_TYPE_YEARS}.
*
* @deprecated Use {@link #isBrowsable} to indicate if an item is a browsable folder and use
* {@link #mediaType} to indicate the type of the folder.
*/
*/
// @Target list includes both 'default' targets and TYPE_USE, to ensure backwards compatibility
// @Target list includes both 'default' targets and TYPE_USE, to ensure backwards compatibility
// with Kotlin usages from before TYPE_USE was added.
// with Kotlin usages from before TYPE_USE was added.
@Documented
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Retention
(
RetentionPolicy
.
SOURCE
)
@Target
({
FIELD
,
METHOD
,
PARAMETER
,
LOCAL_VARIABLE
,
TYPE_USE
})
@Target
({
FIELD
,
METHOD
,
PARAMETER
,
LOCAL_VARIABLE
,
TYPE_USE
})
@Deprecated
@SuppressWarnings
(
"deprecation"
)
// Defining deprecated constants.
@IntDef
({
@IntDef
({
FOLDER_TYPE_NONE
,
FOLDER_TYPE_NONE
,
FOLDER_TYPE_MIXED
,
FOLDER_TYPE_MIXED
,
...
@@ -763,22 +776,60 @@ public final class MediaMetadata implements Bundleable {
...
@@ -763,22 +776,60 @@ public final class MediaMetadata implements Bundleable {
})
})
public
@interface
FolderType
{}
public
@interface
FolderType
{}
/** Type for an item that is not a folder. */
/**
public
static
final
int
FOLDER_TYPE_NONE
=
-
1
;
* Type for an item that is not a folder.
/** Type for a folder containing media of mixed types. */
*
public
static
final
int
FOLDER_TYPE_MIXED
=
0
;
* @deprecated Use {@link #isBrowsable} set to false instead.
/** Type for a folder containing only playable media. */
*/
public
static
final
int
FOLDER_TYPE_TITLES
=
1
;
@Deprecated
public
static
final
int
FOLDER_TYPE_NONE
=
-
1
;
/** Type for a folder containing media categorized by album. */
/**
public
static
final
int
FOLDER_TYPE_ALBUMS
=
2
;
* Type for a folder containing media of mixed types.
/** Type for a folder containing media categorized by artist. */
*
public
static
final
int
FOLDER_TYPE_ARTISTS
=
3
;
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
/** Type for a folder containing media categorized by genre. */
* #MEDIA_TYPE_FOLDER_MIXED} instead.
public
static
final
int
FOLDER_TYPE_GENRES
=
4
;
*/
/** Type for a folder containing a playlist. */
@Deprecated
public
static
final
int
FOLDER_TYPE_MIXED
=
0
;
public
static
final
int
FOLDER_TYPE_PLAYLISTS
=
5
;
/**
/** Type for a folder containing media categorized by year. */
* Type for a folder containing only playable media.
public
static
final
int
FOLDER_TYPE_YEARS
=
6
;
*
* @deprecated Use {@link #isBrowsable} set to true instead.
*/
@Deprecated
public
static
final
int
FOLDER_TYPE_TITLES
=
1
;
/**
* Type for a folder containing media categorized by album.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_ALBUMS} instead.
*/
@Deprecated
public
static
final
int
FOLDER_TYPE_ALBUMS
=
2
;
/**
* Type for a folder containing media categorized by artist.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_ARTISTS} instead.
*/
@Deprecated
public
static
final
int
FOLDER_TYPE_ARTISTS
=
3
;
/**
* Type for a folder containing media categorized by genre.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_GENRES} instead.
*/
@Deprecated
public
static
final
int
FOLDER_TYPE_GENRES
=
4
;
/**
* Type for a folder containing a playlist.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_PLAYLISTS} instead.
*/
@Deprecated
public
static
final
int
FOLDER_TYPE_PLAYLISTS
=
5
;
/**
* Type for a folder containing media categorized by year.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_YEARS} instead.
*/
@Deprecated
public
static
final
int
FOLDER_TYPE_YEARS
=
6
;
/**
/**
* The picture type of the artwork.
* The picture type of the artwork.
...
@@ -887,10 +938,13 @@ public final class MediaMetadata implements Bundleable {
...
@@ -887,10 +938,13 @@ public final class MediaMetadata implements Bundleable {
/**
/**
* Optional {@link FolderType}.
* Optional {@link FolderType}.
*
*
*
<p>This field will be deprecated. Use {@link #isBrowsable} to indicate if an item is a
*
@deprecated Use {@link #isBrowsable} to indicate if an item is a browsable folder and use
*
browsable folder and use
{@link #mediaType} to indicate the type of the folder.
*
{@link #mediaType} to indicate the type of the folder.
*/
*/
@Nullable
public
final
@FolderType
Integer
folderType
;
@SuppressWarnings
(
"deprecation"
)
// Defining field of deprecated type.
@Deprecated
@Nullable
public
final
@FolderType
Integer
folderType
;
/** Optional boolean to indicate that the media is a browsable folder. */
/** Optional boolean to indicate that the media is a browsable folder. */
@Nullable
public
final
Boolean
isBrowsable
;
@Nullable
public
final
Boolean
isBrowsable
;
/** Optional boolean to indicate that the media is playable. */
/** Optional boolean to indicate that the media is playable. */
...
@@ -955,6 +1009,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -955,6 +1009,7 @@ public final class MediaMetadata implements Bundleable {
*/
*/
@Nullable
public
final
Bundle
extras
;
@Nullable
public
final
Bundle
extras
;
@SuppressWarnings
(
"deprecation"
)
// Assigning deprecated fields.
private
MediaMetadata
(
Builder
builder
)
{
private
MediaMetadata
(
Builder
builder
)
{
// Handle compatibility for deprecated fields.
// Handle compatibility for deprecated fields.
@Nullable
Boolean
isBrowsable
=
builder
.
isBrowsable
;
@Nullable
Boolean
isBrowsable
=
builder
.
isBrowsable
;
...
@@ -1013,6 +1068,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -1013,6 +1068,7 @@ public final class MediaMetadata implements Bundleable {
return
new
Builder
(
/* mediaMetadata= */
this
);
return
new
Builder
(
/* mediaMetadata= */
this
);
}
}
@SuppressWarnings
(
"deprecation"
)
// Comparing deprecated fields.
@Override
@Override
public
boolean
equals
(
@Nullable
Object
obj
)
{
public
boolean
equals
(
@Nullable
Object
obj
)
{
if
(
this
==
obj
)
{
if
(
this
==
obj
)
{
...
@@ -1056,6 +1112,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -1056,6 +1112,7 @@ public final class MediaMetadata implements Bundleable {
&&
Util
.
areEqual
(
mediaType
,
that
.
mediaType
);
&&
Util
.
areEqual
(
mediaType
,
that
.
mediaType
);
}
}
@SuppressWarnings
(
"deprecation"
)
// Hashing deprecated fields.
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hashCode
(
return
Objects
.
hashCode
(
...
@@ -1130,6 +1187,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -1130,6 +1187,7 @@ public final class MediaMetadata implements Bundleable {
private
static
final
String
FIELD_IS_BROWSABLE
=
Util
.
intToStringMaxRadix
(
32
);
private
static
final
String
FIELD_IS_BROWSABLE
=
Util
.
intToStringMaxRadix
(
32
);
private
static
final
String
FIELD_EXTRAS
=
Util
.
intToStringMaxRadix
(
1000
);
private
static
final
String
FIELD_EXTRAS
=
Util
.
intToStringMaxRadix
(
1000
);
@SuppressWarnings
(
"deprecation"
)
// Bundling deprecated fields.
@Override
@Override
public
Bundle
toBundle
()
{
public
Bundle
toBundle
()
{
Bundle
bundle
=
new
Bundle
();
Bundle
bundle
=
new
Bundle
();
...
@@ -1238,6 +1296,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -1238,6 +1296,7 @@ public final class MediaMetadata implements Bundleable {
/** Object that can restore {@link MediaMetadata} from a {@link Bundle}. */
/** Object that can restore {@link MediaMetadata} from a {@link Bundle}. */
public
static
final
Creator
<
MediaMetadata
>
CREATOR
=
MediaMetadata:
:
fromBundle
;
public
static
final
Creator
<
MediaMetadata
>
CREATOR
=
MediaMetadata:
:
fromBundle
;
@SuppressWarnings
(
"deprecation"
)
// Unbundling deprecated fields.
private
static
MediaMetadata
fromBundle
(
Bundle
bundle
)
{
private
static
MediaMetadata
fromBundle
(
Bundle
bundle
)
{
Builder
builder
=
new
Builder
();
Builder
builder
=
new
Builder
();
builder
builder
...
@@ -1320,6 +1379,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -1320,6 +1379,7 @@ public final class MediaMetadata implements Bundleable {
return
builder
.
build
();
return
builder
.
build
();
}
}
@SuppressWarnings
(
"deprecation"
)
// Converting deprecated field.
private
static
@FolderType
int
getFolderTypeFromMediaType
(
@MediaType
int
mediaType
)
{
private
static
@FolderType
int
getFolderTypeFromMediaType
(
@MediaType
int
mediaType
)
{
switch
(
mediaType
)
{
switch
(
mediaType
)
{
case
MEDIA_TYPE_ALBUM:
case
MEDIA_TYPE_ALBUM:
...
@@ -1369,6 +1429,7 @@ public final class MediaMetadata implements Bundleable {
...
@@ -1369,6 +1429,7 @@ public final class MediaMetadata implements Bundleable {
}
}
}
}
@SuppressWarnings
(
"deprecation"
)
// Converting deprecated field.
private
static
@MediaType
int
getMediaTypeFromFolderType
(
@FolderType
int
folderType
)
{
private
static
@MediaType
int
getMediaTypeFromFolderType
(
@FolderType
int
folderType
)
{
switch
(
folderType
)
{
switch
(
folderType
)
{
case
FOLDER_TYPE_ALBUMS:
case
FOLDER_TYPE_ALBUMS:
...
...
library/common/src/test/java/com/google/android/exoplayer2/MediaMetadataTest.java
View file @
5e9b0c2f
...
@@ -30,6 +30,7 @@ public class MediaMetadataTest {
...
@@ -30,6 +30,7 @@ public class MediaMetadataTest {
private
static
final
String
EXTRAS_KEY
=
"exampleKey"
;
private
static
final
String
EXTRAS_KEY
=
"exampleKey"
;
private
static
final
String
EXTRAS_VALUE
=
"exampleValue"
;
private
static
final
String
EXTRAS_VALUE
=
"exampleValue"
;
@SuppressWarnings
(
"deprecation"
)
// Testing deprecated field.
@Test
@Test
public
void
builder_minimal_correctDefaults
()
{
public
void
builder_minimal_correctDefaults
()
{
MediaMetadata
mediaMetadata
=
new
MediaMetadata
.
Builder
().
build
();
MediaMetadata
mediaMetadata
=
new
MediaMetadata
.
Builder
().
build
();
...
@@ -134,6 +135,7 @@ public class MediaMetadataTest {
...
@@ -134,6 +135,7 @@ public class MediaMetadataTest {
assertThat
(
mediaMetadataFromBundle
.
extras
.
getString
(
EXTRAS_KEY
)).
isEqualTo
(
EXTRAS_VALUE
);
assertThat
(
mediaMetadataFromBundle
.
extras
.
getString
(
EXTRAS_KEY
)).
isEqualTo
(
EXTRAS_VALUE
);
}
}
@SuppressWarnings
(
"deprecation"
)
// Testing deprecated setter.
@Test
@Test
public
void
builderSetFolderType_toNone_setsIsBrowsableToFalse
()
{
public
void
builderSetFolderType_toNone_setsIsBrowsableToFalse
()
{
MediaMetadata
mediaMetadata
=
MediaMetadata
mediaMetadata
=
...
@@ -142,6 +144,7 @@ public class MediaMetadataTest {
...
@@ -142,6 +144,7 @@ public class MediaMetadataTest {
assertThat
(
mediaMetadata
.
isBrowsable
).
isFalse
();
assertThat
(
mediaMetadata
.
isBrowsable
).
isFalse
();
}
}
@SuppressWarnings
(
"deprecation"
)
// Testing deprecated setter.
@Test
@Test
public
void
builderSetFolderType_toNotNone_setsIsBrowsableToTrueAndMatchingMediaType
()
{
public
void
builderSetFolderType_toNotNone_setsIsBrowsableToTrueAndMatchingMediaType
()
{
MediaMetadata
mediaMetadata
=
MediaMetadata
mediaMetadata
=
...
@@ -151,6 +154,7 @@ public class MediaMetadataTest {
...
@@ -151,6 +154,7 @@ public class MediaMetadataTest {
assertThat
(
mediaMetadata
.
mediaType
).
isEqualTo
(
MediaMetadata
.
MEDIA_TYPE_FOLDER_PLAYLISTS
);
assertThat
(
mediaMetadata
.
mediaType
).
isEqualTo
(
MediaMetadata
.
MEDIA_TYPE_FOLDER_PLAYLISTS
);
}
}
@SuppressWarnings
(
"deprecation"
)
// Testing deprecated setter.
@Test
@Test
public
void
public
void
builderSetFolderType_toNotNoneWithManualMediaType_setsIsBrowsableToTrueAndDoesNotOverrideMediaType
()
{
builderSetFolderType_toNotNoneWithManualMediaType_setsIsBrowsableToTrueAndDoesNotOverrideMediaType
()
{
...
@@ -164,6 +168,7 @@ public class MediaMetadataTest {
...
@@ -164,6 +168,7 @@ public class MediaMetadataTest {
assertThat
(
mediaMetadata
.
mediaType
).
isEqualTo
(
MediaMetadata
.
MEDIA_TYPE_FOLDER_PODCASTS
);
assertThat
(
mediaMetadata
.
mediaType
).
isEqualTo
(
MediaMetadata
.
MEDIA_TYPE_FOLDER_PODCASTS
);
}
}
@SuppressWarnings
(
"deprecation"
)
// Testing deprecated field.
@Test
@Test
public
void
builderSetIsBrowsable_toTrueWithoutMediaType_setsFolderTypeToMixed
()
{
public
void
builderSetIsBrowsable_toTrueWithoutMediaType_setsFolderTypeToMixed
()
{
MediaMetadata
mediaMetadata
=
new
MediaMetadata
.
Builder
().
setIsBrowsable
(
true
).
build
();
MediaMetadata
mediaMetadata
=
new
MediaMetadata
.
Builder
().
setIsBrowsable
(
true
).
build
();
...
@@ -171,6 +176,7 @@ public class MediaMetadataTest {
...
@@ -171,6 +176,7 @@ public class MediaMetadataTest {
assertThat
(
mediaMetadata
.
folderType
).
isEqualTo
(
MediaMetadata
.
FOLDER_TYPE_MIXED
);
assertThat
(
mediaMetadata
.
folderType
).
isEqualTo
(
MediaMetadata
.
FOLDER_TYPE_MIXED
);
}
}
@SuppressWarnings
(
"deprecation"
)
// Testing deprecated field.
@Test
@Test
public
void
builderSetIsBrowsable_toTrueWithMediaType_setsFolderTypeToMatchMediaType
()
{
public
void
builderSetIsBrowsable_toTrueWithMediaType_setsFolderTypeToMatchMediaType
()
{
MediaMetadata
mediaMetadata
=
MediaMetadata
mediaMetadata
=
...
@@ -182,6 +188,7 @@ public class MediaMetadataTest {
...
@@ -182,6 +188,7 @@ public class MediaMetadataTest {
assertThat
(
mediaMetadata
.
folderType
).
isEqualTo
(
MediaMetadata
.
FOLDER_TYPE_ARTISTS
);
assertThat
(
mediaMetadata
.
folderType
).
isEqualTo
(
MediaMetadata
.
FOLDER_TYPE_ARTISTS
);
}
}
@SuppressWarnings
(
"deprecation"
)
// Testing deprecated field.
@Test
@Test
public
void
builderSetFolderType_toFalse_setsFolderTypeToNone
()
{
public
void
builderSetFolderType_toFalse_setsFolderTypeToNone
()
{
MediaMetadata
mediaMetadata
=
new
MediaMetadata
.
Builder
().
setIsBrowsable
(
false
).
build
();
MediaMetadata
mediaMetadata
=
new
MediaMetadata
.
Builder
().
setIsBrowsable
(
false
).
build
();
...
@@ -189,6 +196,7 @@ public class MediaMetadataTest {
...
@@ -189,6 +196,7 @@ public class MediaMetadataTest {
assertThat
(
mediaMetadata
.
folderType
).
isEqualTo
(
MediaMetadata
.
FOLDER_TYPE_NONE
);
assertThat
(
mediaMetadata
.
folderType
).
isEqualTo
(
MediaMetadata
.
FOLDER_TYPE_NONE
);
}
}
@SuppressWarnings
(
"deprecation"
)
// Setting deprecated fields.
private
static
MediaMetadata
getFullyPopulatedMediaMetadata
()
{
private
static
MediaMetadata
getFullyPopulatedMediaMetadata
()
{
Bundle
extras
=
new
Bundle
();
Bundle
extras
=
new
Bundle
();
extras
.
putString
(
EXTRAS_KEY
,
EXTRAS_VALUE
);
extras
.
putString
(
EXTRAS_KEY
,
EXTRAS_VALUE
);
...
...
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