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
eaf0d408
authored
Feb 16, 2019
by
Arnold Szabo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Extract time bar delay calculations to a static method
parent
ecfce462
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
30 deletions
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java
View file @
eaf0d408
...
@@ -837,36 +837,7 @@ public class PlayerControlView extends FrameLayout {
...
@@ -837,36 +837,7 @@ public class PlayerControlView extends FrameLayout {
if
(
player
.
getPlayWhenReady
()
&&
playbackState
==
Player
.
STATE_READY
)
{
if
(
player
.
getPlayWhenReady
()
&&
playbackState
==
Player
.
STATE_READY
)
{
float
playbackSpeed
=
player
.
getPlaybackParameters
().
speed
;
float
playbackSpeed
=
player
.
getPlaybackParameters
().
speed
;
int
timeBarWidth
=
timeBar
.
getTimeBarWidthDp
();
int
timeBarWidth
=
timeBar
.
getTimeBarWidthDp
();
delayMs
=
getTimeBarUpdateDelayMs
(
timeBarWidth
,
position
,
duration
,
playbackSpeed
);
if
(
timeBarWidth
==
0
||
duration
==
0
)
{
delayMs
=
MAX_UPDATE_FREQUENCY_MS
;
}
else
{
// Calculate how many updates needs to be done with DEFAULT_UPDATE_DP
// to fill up the time bar
int
numberOfUpdates
=
timeBarWidth
/
DEFAULT_UPDATE_DP
;
// Calculate the designated update interval, taking duration into consideration as well
long
mediaTimeUpdatePeriodMs
=
duration
/
numberOfUpdates
;
// Calculate the delay needed from the current position until the next update is due
long
mediaTimeDelayMs
=
mediaTimeUpdatePeriodMs
-
(
position
%
mediaTimeUpdatePeriodMs
);
// If the delay would be too small, then skip the next update
if
(
mediaTimeDelayMs
<
(
mediaTimeUpdatePeriodMs
/
5
))
{
mediaTimeDelayMs
+=
mediaTimeUpdatePeriodMs
;
}
// Calculate the delay until the next update (in real time), taking
// playbackSpeed into consideration
delayMs
=
playbackSpeed
==
1
?
mediaTimeDelayMs
:
(
long
)
(
mediaTimeDelayMs
/
playbackSpeed
);
// Limit the delay if needed, to avoid too frequent / infrequent updates
if
(
delayMs
<
MIN_UPDATE_FREQUENCY_MS
)
{
delayMs
=
MIN_UPDATE_FREQUENCY_MS
;
}
else
if
(
delayMs
>=
MAX_UPDATE_FREQUENCY_MS
)
{
delayMs
=
MAX_UPDATE_FREQUENCY_MS
;
}
}
}
else
{
}
else
{
delayMs
=
MAX_UPDATE_FREQUENCY_MS
;
delayMs
=
MAX_UPDATE_FREQUENCY_MS
;
}
}
...
@@ -1097,6 +1068,58 @@ public class PlayerControlView extends FrameLayout {
...
@@ -1097,6 +1068,58 @@ public class PlayerControlView extends FrameLayout {
return
true
;
return
true
;
}
}
/**
* Calculates the update delay of time bar in millis
*
* @param timeBarWidth The width of time bar in dp
* @param position The current position in millis
* @param duration The duration of media in millis
* @param playbackSpeed The playback speed
* @return Update delay of time bar in millis
*/
private
static
long
getTimeBarUpdateDelayMs
(
int
timeBarWidth
,
long
position
,
long
duration
,
float
playbackSpeed
)
{
if
(
timeBarWidth
==
0
||
duration
==
0
||
playbackSpeed
==
0
)
{
return
MAX_UPDATE_FREQUENCY_MS
;
}
// Calculate how many updates needs to be done with DEFAULT_UPDATE_DP
// to fill up the time bar
int
numberOfUpdates
=
timeBarWidth
/
DEFAULT_UPDATE_DP
;
if
(
numberOfUpdates
<=
0
)
{
return
MAX_UPDATE_FREQUENCY_MS
;
}
// Calculate the designated update interval, taking duration into consideration as well
long
mediaTimeUpdatePeriodMs
=
duration
/
numberOfUpdates
;
if
(
mediaTimeUpdatePeriodMs
<=
0
)
{
return
MAX_UPDATE_FREQUENCY_MS
;
}
// Calculate the delay needed from the current position until the next update is due
long
mediaTimeDelayMs
=
mediaTimeUpdatePeriodMs
-
(
position
%
mediaTimeUpdatePeriodMs
);
// If the delay would be too small, then skip the next update
if
(
mediaTimeDelayMs
<
(
mediaTimeUpdatePeriodMs
/
5
))
{
mediaTimeDelayMs
+=
mediaTimeUpdatePeriodMs
;
}
// Calculate the delay until the next update (in real time), taking
// playbackSpeed into consideration
long
delayMs
=
playbackSpeed
==
1
?
mediaTimeDelayMs
:
(
long
)
(
mediaTimeDelayMs
/
playbackSpeed
);
// Limit the delay if needed, to avoid too frequent / infrequent updates
if
(
delayMs
<
MIN_UPDATE_FREQUENCY_MS
)
{
delayMs
=
MIN_UPDATE_FREQUENCY_MS
;
}
else
if
(
delayMs
>=
MAX_UPDATE_FREQUENCY_MS
)
{
delayMs
=
MAX_UPDATE_FREQUENCY_MS
;
}
return
delayMs
;
}
private
final
class
ComponentListener
private
final
class
ComponentListener
implements
Player
.
EventListener
,
TimeBar
.
OnScrubListener
,
OnClickListener
{
implements
Player
.
EventListener
,
TimeBar
.
OnScrubListener
,
OnClickListener
{
...
...
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