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
58e01671
authored
Nov 24, 2020
by
bachinger
Committed by
Andrew Lewis
Nov 27, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use onEvents in MediaSessionConnector to avoid multiple updates.
#exofixit PiperOrigin-RevId: 344065556
parent
c17d1091
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
56 deletions
extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java
extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java
View file @
58e01671
...
@@ -15,6 +15,13 @@
...
@@ -15,6 +15,13 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
ext
.
mediasession
;
package
com
.
google
.
android
.
exoplayer2
.
ext
.
mediasession
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_PARAMETERS_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_STATE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAY_WHEN_READY_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_REPEAT_MODE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_SHUFFLE_MODE_ENABLED_CHANGED
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
import
android.net.Uri
;
import
android.net.Uri
;
...
@@ -38,7 +45,6 @@ import com.google.android.exoplayer2.ControlDispatcher;
...
@@ -38,7 +45,6 @@ import com.google.android.exoplayer2.ControlDispatcher;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.ExoPlaybackException
;
import
com.google.android.exoplayer2.ExoPlaybackException
;
import
com.google.android.exoplayer2.ExoPlayerLibraryInfo
;
import
com.google.android.exoplayer2.ExoPlayerLibraryInfo
;
import
com.google.android.exoplayer2.PlaybackParameters
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Assertions
;
...
@@ -1074,69 +1080,59 @@ public final class MediaSessionConnector {
...
@@ -1074,69 +1080,59 @@ public final class MediaSessionConnector {
// Player.EventListener implementation.
// Player.EventListener implementation.
@Override
@Override
public
void
onTimelineChanged
(
Timeline
timeline
,
@Player
.
TimelineChangeReason
int
reason
)
{
public
void
onEvents
(
Player
player
,
Player
.
Events
events
)
{
Player
player
=
Assertions
.
checkNotNull
(
MediaSessionConnector
.
this
.
player
);
boolean
invalidatePlaybackState
=
false
;
int
windowCount
=
player
.
getCurrentTimeline
().
getWindowCount
();
boolean
invalidateMetadata
=
false
;
int
windowIndex
=
player
.
getCurrentWindowIndex
();
if
(
events
.
contains
(
Player
.
EVENT_POSITION_DISCONTINUITY
))
{
if
(
queueNavigator
!=
null
)
{
if
(
currentWindowIndex
!=
player
.
getCurrentWindowIndex
())
{
queueNavigator
.
onTimelineChanged
(
player
);
if
(
queueNavigator
!=
null
)
{
invalidateMediaSessionPlaybackState
();
queueNavigator
.
onCurrentWindowIndexChanged
(
player
);
}
else
if
(
currentWindowCount
!=
windowCount
||
currentWindowIndex
!=
windowIndex
)
{
}
// active queue item and queue navigation actions may need to be updated
invalidateMetadata
=
true
;
invalidateMediaSessionPlaybackState
();
}
invalidatePlaybackState
=
true
;
}
}
currentWindowCount
=
windowCount
;
currentWindowIndex
=
windowIndex
;
invalidateMediaSessionMetadata
();
}
@Override
if
(
events
.
contains
(
Player
.
EVENT_TIMELINE_CHANGED
))
{
public
void
onPlaybackStateChanged
(
@Player
.
State
int
playbackState
)
{
int
windowCount
=
player
.
getCurrentTimeline
().
getWindowCount
();
invalidateMediaSessionPlaybackState
();
int
windowIndex
=
player
.
getCurrentWindowIndex
();
}
if
(
queueNavigator
!=
null
)
{
queueNavigator
.
onTimelineChanged
(
player
);
@Override
invalidatePlaybackState
=
true
;
public
void
onPlayWhenReadyChanged
(
}
else
if
(
currentWindowCount
!=
windowCount
||
currentWindowIndex
!=
windowIndex
)
{
boolean
playWhenReady
,
@Player
.
PlayWhenReadyChangeReason
int
reason
)
{
// active queue item and queue navigation actions may need to be updated
invalidateMediaSessionPlaybackState
();
invalidatePlaybackState
=
true
;
}
}
currentWindowCount
=
windowCount
;
@Override
invalidateMetadata
=
true
;
public
void
onIsPlayingChanged
(
boolean
isPlaying
)
{
}
invalidateMediaSessionPlaybackState
();
}
@Override
// Update currentWindowIndex after comparisons above.
public
void
onRepeatModeChanged
(
@Player
.
RepeatMode
int
repeatMode
)
{
currentWindowIndex
=
player
.
getCurrentWindowIndex
();
invalidateMediaSessionPlaybackState
();
}
@Override
if
(
events
.
containsAny
(
public
void
onShuffleModeEnabledChanged
(
boolean
shuffleModeEnabled
)
{
EVENT_PLAYBACK_STATE_CHANGED
,
invalidateMediaSessionPlaybackState
();
EVENT_PLAY_WHEN_READY_CHANGED
,
invalidateMediaSessionQueue
();
EVENT_IS_PLAYING_CHANGED
,
}
EVENT_REPEAT_MODE_CHANGED
,
EVENT_PLAYBACK_PARAMETERS_CHANGED
))
{
invalidatePlaybackState
=
true
;
}
@Override
// The queue needs to be updated by the queue navigator first. The queue navigator also
public
void
onPositionDiscontinuity
(
@Player
.
DiscontinuityReason
int
reason
)
{
// delivers the active queue item that is used to update the playback state.
Player
player
=
Assertions
.
checkNotNull
(
MediaSessionConnector
.
this
.
player
);
if
(
events
.
containsAny
(
EVENT_SHUFFLE_MODE_ENABLED_CHANGED
))
{
if
(
currentWindowIndex
!=
player
.
getCurrentWindowIndex
())
{
invalidateMediaSessionQueue
();
if
(
queueNavigator
!=
null
)
{
invalidatePlaybackState
=
true
;
queueNavigator
.
onCurrentWindowIndexChanged
(
player
);
}
}
// Invalidate the playback state before invalidating metadata because the active queue item of
currentWindowIndex
=
player
.
getCurrentWindowIndex
();
// the session playback state needs to be updated before the MediaMetadataProvider uses it.
// Update playback state after queueNavigator.onCurrentWindowIndexChanged has been called
if
(
invalidatePlaybackState
)
{
// and before updating metadata.
invalidateMediaSessionPlaybackState
();
invalidateMediaSessionPlaybackState
();
}
if
(
invalidateMetadata
)
{
invalidateMediaSessionMetadata
();
invalidateMediaSessionMetadata
();
return
;
}
}
invalidateMediaSessionPlaybackState
();
}
@Override
public
void
onPlaybackParametersChanged
(
PlaybackParameters
playbackParameters
)
{
invalidateMediaSessionPlaybackState
();
}
}
// MediaSessionCompat.Callback implementation.
// MediaSessionCompat.Callback implementation.
...
...
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