Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Casanowow Life for love
VLC-Android
Commits
61ad7bd0
Commit
61ad7bd0
authored
Apr 13, 2018
by
Geoffrey Métais
Browse files
Limit excessive publishstate calls
parent
a8d248b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
vlc-android/src/org/videolan/vlc/PlaybackService.java
View file @
61ad7bd0
...
...
@@ -116,6 +116,7 @@ public class PlaybackService extends MediaBrowserServiceCompat{
private
static
final
int
SHOW_PROGRESS
=
0
;
private
static
final
int
SHOW_TOAST
=
1
;
private
static
final
int
END_MEDIASESSION
=
2
;
private
static
final
int
PUBLISH_STATE
=
3
;
private
static
final
long
DELAY_DOUBLE_CLICK
=
800L
;
private
static
final
long
DELAY_LONG_CLICK
=
1000L
;
...
...
@@ -529,7 +530,7 @@ public class PlaybackService extends MediaBrowserServiceCompat{
break
;
case
MediaPlayer
.
Event
.
PositionChanged
:
updateWidgetPosition
(
event
.
getPositionChanged
());
publishState
(
);
mHandler
.
sendEmptyMessage
(
PUBLISH_STATE
);
break
;
case
MediaPlayer
.
Event
.
Vout
:
break
;
...
...
@@ -590,6 +591,8 @@ public class PlaybackService extends MediaBrowserServiceCompat{
private
final
Handler
mHandler
=
new
PlaybackServiceHandler
(
this
);
private
static
class
PlaybackServiceHandler
extends
WeakHandler
<
PlaybackService
>
{
private
long
lastPublicationDate
=
0L
;
PlaybackServiceHandler
(
PlaybackService
fragment
)
{
super
(
fragment
);
}
...
...
@@ -617,6 +620,13 @@ public class PlaybackService extends MediaBrowserServiceCompat{
case
END_MEDIASESSION:
if
(
service
.
mMediaSession
!=
null
)
service
.
mMediaSession
.
setActive
(
false
);
break
;
case
PUBLISH_STATE:
final
long
time
=
System
.
currentTimeMillis
();
if
(
time
-
lastPublicationDate
>
1000L
)
{
service
.
publishState
();
lastPublicationDate
=
time
;
}
break
;
}
}
}
...
...
@@ -1053,15 +1063,18 @@ public class PlaybackService extends MediaBrowserServiceCompat{
pscb
.
addCustomAction
(
"repeat"
,
getString
(
R
.
string
.
repeat_title
),
repeatResId
);
boolean
mediaIsActive
=
state
!=
PlaybackStateCompat
.
STATE_STOPPED
;
boolean
update
=
mMediaSession
.
isActive
()
!=
mediaIsActive
;
mMediaSession
.
setPlaybackState
(
pscb
.
build
());
mMediaSession
.
setActive
(
mediaIsActive
);
mMediaSession
.
setQueueTitle
(
getString
(
R
.
string
.
music_now_playing
));
if
(
mediaIsActive
)
sendStartSessionIdIntent
();
else
sendStopSessionIdIntent
();
if
(
update
)
{
if
(
mediaIsActive
)
sendStartSessionIdIntent
();
else
sendStopSessionIdIntent
();
}
}
private
void
notifyTrackChanged
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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