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
0b0277af
authored
Jul 20, 2021
by
samrobinson
Committed by
Ian Baker
Jul 21, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Set StyledPlayerView/PlayerView artwork from MediaMetadata.
PiperOrigin-RevId: 385763366
parent
c157db69
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
66 deletions
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java
View file @
0b0277af
...
@@ -49,15 +49,13 @@ import com.google.android.exoplayer2.C;
...
@@ -49,15 +49,13 @@ import com.google.android.exoplayer2.C;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.ForwardingPlayer
;
import
com.google.android.exoplayer2.ForwardingPlayer
;
import
com.google.android.exoplayer2.MediaMetadata
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Player.DiscontinuityReason
;
import
com.google.android.exoplayer2.Player.DiscontinuityReason
;
import
com.google.android.exoplayer2.SimpleExoPlayer
;
import
com.google.android.exoplayer2.SimpleExoPlayer
;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.Timeline.Period
;
import
com.google.android.exoplayer2.Timeline.Period
;
import
com.google.android.exoplayer2.metadata.Metadata
;
import
com.google.android.exoplayer2.metadata.flac.PictureFrame
;
import
com.google.android.exoplayer2.metadata.id3.ApicFrame
;
import
com.google.android.exoplayer2.source.TrackGroupArray
;
import
com.google.android.exoplayer2.source.TrackGroupArray
;
import
com.google.android.exoplayer2.text.Cue
;
import
com.google.android.exoplayer2.text.Cue
;
import
com.google.android.exoplayer2.trackselection.TrackSelection
;
import
com.google.android.exoplayer2.trackselection.TrackSelection
;
...
@@ -1288,10 +1286,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
...
@@ -1288,10 +1286,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
closeShutter
();
closeShutter
();
// Display artwork if enabled and available, else hide it.
// Display artwork if enabled and available, else hide it.
if
(
useArtwork
())
{
if
(
useArtwork
())
{
for
(
Metadata
metadata
:
player
.
getCurrentStaticMetadata
())
{
if
(
setArtworkFromMediaMetadata
(
player
.
getMediaMetadata
()))
{
if
(
setArtworkFromMetadata
(
metadata
))
{
return
;
return
;
}
}
}
if
(
setDrawableArtwork
(
defaultArtwork
))
{
if
(
setDrawableArtwork
(
defaultArtwork
))
{
return
;
return
;
...
@@ -1334,33 +1330,14 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
...
@@ -1334,33 +1330,14 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
}
}
@RequiresNonNull
(
"artworkView"
)
@RequiresNonNull
(
"artworkView"
)
private
boolean
setArtworkFromMetadata
(
Metadata
metadata
)
{
private
boolean
setArtworkFromMediaMetadata
(
MediaMetadata
mediaMetadata
)
{
boolean
isArtworkSet
=
false
;
if
(
mediaMetadata
.
artworkData
==
null
)
{
int
currentPictureType
=
PICTURE_TYPE_NOT_SET
;
return
false
;
for
(
int
i
=
0
;
i
<
metadata
.
length
();
i
++)
{
Metadata
.
Entry
metadataEntry
=
metadata
.
get
(
i
);
int
pictureType
;
byte
[]
bitmapData
;
if
(
metadataEntry
instanceof
ApicFrame
)
{
bitmapData
=
((
ApicFrame
)
metadataEntry
).
pictureData
;
pictureType
=
((
ApicFrame
)
metadataEntry
).
pictureType
;
}
else
if
(
metadataEntry
instanceof
PictureFrame
)
{
bitmapData
=
((
PictureFrame
)
metadataEntry
).
pictureData
;
pictureType
=
((
PictureFrame
)
metadataEntry
).
pictureType
;
}
else
{
continue
;
}
// Prefer the first front cover picture. If there aren't any, prefer the first picture.
if
(
currentPictureType
==
PICTURE_TYPE_NOT_SET
||
pictureType
==
PICTURE_TYPE_FRONT_COVER
)
{
Bitmap
bitmap
=
BitmapFactory
.
decodeByteArray
(
bitmapData
,
0
,
bitmapData
.
length
);
isArtworkSet
=
setDrawableArtwork
(
new
BitmapDrawable
(
getResources
(),
bitmap
));
currentPictureType
=
pictureType
;
if
(
currentPictureType
==
PICTURE_TYPE_FRONT_COVER
)
{
break
;
}
}
}
}
return
isArtworkSet
;
Bitmap
bitmap
=
BitmapFactory
.
decodeByteArray
(
mediaMetadata
.
artworkData
,
/* offset= */
0
,
mediaMetadata
.
artworkData
.
length
);
return
setDrawableArtwork
(
new
BitmapDrawable
(
getResources
(),
bitmap
));
}
}
@RequiresNonNull
(
"artworkView"
)
@RequiresNonNull
(
"artworkView"
)
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java
View file @
0b0277af
...
@@ -50,15 +50,13 @@ import com.google.android.exoplayer2.C;
...
@@ -50,15 +50,13 @@ import com.google.android.exoplayer2.C;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.ForwardingPlayer
;
import
com.google.android.exoplayer2.ForwardingPlayer
;
import
com.google.android.exoplayer2.MediaMetadata
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Player.DiscontinuityReason
;
import
com.google.android.exoplayer2.Player.DiscontinuityReason
;
import
com.google.android.exoplayer2.SimpleExoPlayer
;
import
com.google.android.exoplayer2.SimpleExoPlayer
;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.Timeline.Period
;
import
com.google.android.exoplayer2.Timeline.Period
;
import
com.google.android.exoplayer2.metadata.Metadata
;
import
com.google.android.exoplayer2.metadata.flac.PictureFrame
;
import
com.google.android.exoplayer2.metadata.id3.ApicFrame
;
import
com.google.android.exoplayer2.source.TrackGroupArray
;
import
com.google.android.exoplayer2.source.TrackGroupArray
;
import
com.google.android.exoplayer2.text.Cue
;
import
com.google.android.exoplayer2.text.Cue
;
import
com.google.android.exoplayer2.trackselection.TrackSelection
;
import
com.google.android.exoplayer2.trackselection.TrackSelection
;
...
@@ -1329,10 +1327,8 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
...
@@ -1329,10 +1327,8 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
closeShutter
();
closeShutter
();
// Display artwork if enabled and available, else hide it.
// Display artwork if enabled and available, else hide it.
if
(
useArtwork
())
{
if
(
useArtwork
())
{
for
(
Metadata
metadata
:
player
.
getCurrentStaticMetadata
())
{
if
(
setArtworkFromMediaMetadata
(
player
.
getMediaMetadata
()))
{
if
(
setArtworkFromMetadata
(
metadata
))
{
return
;
return
;
}
}
}
if
(
setDrawableArtwork
(
defaultArtwork
))
{
if
(
setDrawableArtwork
(
defaultArtwork
))
{
return
;
return
;
...
@@ -1343,33 +1339,14 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
...
@@ -1343,33 +1339,14 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
}
}
@RequiresNonNull
(
"artworkView"
)
@RequiresNonNull
(
"artworkView"
)
private
boolean
setArtworkFromMetadata
(
Metadata
metadata
)
{
private
boolean
setArtworkFromMediaMetadata
(
MediaMetadata
mediaMetadata
)
{
boolean
isArtworkSet
=
false
;
if
(
mediaMetadata
.
artworkData
==
null
)
{
int
currentPictureType
=
PICTURE_TYPE_NOT_SET
;
return
false
;
for
(
int
i
=
0
;
i
<
metadata
.
length
();
i
++)
{
Metadata
.
Entry
metadataEntry
=
metadata
.
get
(
i
);
int
pictureType
;
byte
[]
bitmapData
;
if
(
metadataEntry
instanceof
ApicFrame
)
{
bitmapData
=
((
ApicFrame
)
metadataEntry
).
pictureData
;
pictureType
=
((
ApicFrame
)
metadataEntry
).
pictureType
;
}
else
if
(
metadataEntry
instanceof
PictureFrame
)
{
bitmapData
=
((
PictureFrame
)
metadataEntry
).
pictureData
;
pictureType
=
((
PictureFrame
)
metadataEntry
).
pictureType
;
}
else
{
continue
;
}
// Prefer the first front cover picture. If there aren't any, prefer the first picture.
if
(
currentPictureType
==
PICTURE_TYPE_NOT_SET
||
pictureType
==
PICTURE_TYPE_FRONT_COVER
)
{
Bitmap
bitmap
=
BitmapFactory
.
decodeByteArray
(
bitmapData
,
0
,
bitmapData
.
length
);
isArtworkSet
=
setDrawableArtwork
(
new
BitmapDrawable
(
getResources
(),
bitmap
));
currentPictureType
=
pictureType
;
if
(
currentPictureType
==
PICTURE_TYPE_FRONT_COVER
)
{
break
;
}
}
}
}
return
isArtworkSet
;
Bitmap
bitmap
=
BitmapFactory
.
decodeByteArray
(
mediaMetadata
.
artworkData
,
/* offset= */
0
,
mediaMetadata
.
artworkData
.
length
);
return
setDrawableArtwork
(
new
BitmapDrawable
(
getResources
(),
bitmap
));
}
}
@RequiresNonNull
(
"artworkView"
)
@RequiresNonNull
(
"artworkView"
)
...
...
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