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
74a9bf09
authored
Mar 02, 2021
by
olly
Committed by
marcbaechinger
Apr 09, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Simplify handling of playback speed in StyledPlayerControlView
PiperOrigin-RevId: 360404403
parent
14711d1f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
73 deletions
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java
View file @
74a9bf09
...
...
@@ -436,14 +436,10 @@ public class StyledPlayerControlView extends FrameLayout {
private
StyledPlayerControlViewLayoutManager
controlViewLayoutManager
;
private
Resources
resources
;
private
int
selectedMainSettingsPosition
;
private
RecyclerView
settingsView
;
private
SettingsAdapter
settingsAdapter
;
private
SubSettingsAdapter
subSettings
Adapter
;
private
PlaybackSpeedAdapter
playbackSpeed
Adapter
;
private
PopupWindow
settingsWindow
;
private
String
[]
playbackSpeedTexts
;
private
int
[]
playbackSpeedsMultBy100
;
private
int
selectedPlaybackSpeedIndex
;
private
boolean
needToHideBars
;
private
int
settingsWindowMargin
;
...
...
@@ -675,12 +671,7 @@ public class StyledPlayerControlView extends FrameLayout {
settingIcons
[
SETTINGS_AUDIO_TRACK_SELECTION_POSITION
]
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_audiotrack
);
settingsAdapter
=
new
SettingsAdapter
(
settingTexts
,
settingIcons
);
playbackSpeedTexts
=
resources
.
getStringArray
(
R
.
array
.
exo_playback_speeds
);
playbackSpeedsMultBy100
=
resources
.
getIntArray
(
R
.
array
.
exo_speed_multiplied_by_100
);
settingsWindowMargin
=
resources
.
getDimensionPixelSize
(
R
.
dimen
.
exo_settings_offset
);
subSettingsAdapter
=
new
SubSettingsAdapter
();
settingsView
=
(
RecyclerView
)
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
exo_styled_settings_list
,
null
);
...
...
@@ -705,6 +696,10 @@ public class StyledPlayerControlView extends FrameLayout {
resources
.
getString
(
R
.
string
.
exo_controls_cc_disabled_description
);
textTrackSelectionAdapter
=
new
TextTrackSelectionAdapter
();
audioTrackSelectionAdapter
=
new
AudioTrackSelectionAdapter
();
playbackSpeedAdapter
=
new
PlaybackSpeedAdapter
(
resources
.
getStringArray
(
R
.
array
.
exo_playback_speeds
),
resources
.
getIntArray
(
R
.
array
.
exo_speed_multiplied_by_100
));
fullScreenExitDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_fullscreen_exit
);
fullScreenEnterDrawable
=
...
...
@@ -782,7 +777,6 @@ public class StyledPlayerControlView extends FrameLayout {
this
.
trackSelector
=
null
;
}
updateAll
();
updateSettingsPlaybackSpeedLists
();
}
/**
...
...
@@ -1114,6 +1108,7 @@ public class StyledPlayerControlView extends FrameLayout {
updateRepeatModeButton
();
updateShuffleButton
();
updateTrackLists
();
updatePlaybackSpeedList
();
updateTimeline
();
}
...
...
@@ -1449,24 +1444,13 @@ public class StyledPlayerControlView extends FrameLayout {
}
}
private
void
update
SettingsPlaybackSpeedLists
()
{
private
void
update
PlaybackSpeedList
()
{
if
(
player
==
null
)
{
return
;
}
float
speed
=
player
.
getPlaybackParameters
().
speed
;
int
currentSpeedMultBy100
=
Math
.
round
(
speed
*
100
);
int
closestMatchIndex
=
0
;
int
closestMatchDifference
=
Integer
.
MAX_VALUE
;
for
(
int
i
=
0
;
i
<
playbackSpeedsMultBy100
.
length
;
i
++)
{
int
difference
=
Math
.
abs
(
currentSpeedMultBy100
-
playbackSpeedsMultBy100
[
i
]);
if
(
difference
<
closestMatchDifference
)
{
closestMatchIndex
=
i
;
closestMatchDifference
=
difference
;
}
}
selectedPlaybackSpeedIndex
=
closestMatchIndex
;
playbackSpeedAdapter
.
updateSelectedIndex
(
player
.
getPlaybackParameters
().
speed
);
settingsAdapter
.
setSubTextAtPosition
(
SETTINGS_PLAYBACK_SPEED_POSITION
,
playbackSpeed
Texts
[
closestMatchIndex
]
);
SETTINGS_PLAYBACK_SPEED_POSITION
,
playbackSpeed
Adapter
.
getSelectedText
()
);
}
private
void
updateSettingsWindowSize
()
{
...
...
@@ -1582,27 +1566,14 @@ public class StyledPlayerControlView extends FrameLayout {
private
void
onSettingViewClicked
(
int
position
)
{
if
(
position
==
SETTINGS_PLAYBACK_SPEED_POSITION
)
{
subSettingsAdapter
.
init
(
playbackSpeedTexts
,
selectedPlaybackSpeedIndex
);
selectedMainSettingsPosition
=
SETTINGS_PLAYBACK_SPEED_POSITION
;
displaySettingsWindow
(
subSettingsAdapter
);
displaySettingsWindow
(
playbackSpeedAdapter
);
}
else
if
(
position
==
SETTINGS_AUDIO_TRACK_SELECTION_POSITION
)
{
selectedMainSettingsPosition
=
SETTINGS_AUDIO_TRACK_SELECTION_POSITION
;
displaySettingsWindow
(
audioTrackSelectionAdapter
);
}
else
{
settingsWindow
.
dismiss
();
}
}
private
void
onSubSettingViewClicked
(
int
position
)
{
if
(
selectedMainSettingsPosition
==
SETTINGS_PLAYBACK_SPEED_POSITION
)
{
if
(
position
!=
selectedPlaybackSpeedIndex
)
{
float
speed
=
playbackSpeedsMultBy100
[
position
]
/
100.0f
;
setPlaybackSpeed
(
speed
);
}
}
settingsWindow
.
dismiss
();
}
private
void
onLayoutChange
(
View
v
,
int
left
,
...
...
@@ -1847,7 +1818,7 @@ public class StyledPlayerControlView extends FrameLayout {
updateTimeline
();
}
if
(
events
.
contains
(
EVENT_PLAYBACK_PARAMETERS_CHANGED
))
{
update
SettingsPlaybackSpeedLists
();
update
PlaybackSpeedList
();
}
if
(
events
.
contains
(
EVENT_TRACKS_CHANGED
))
{
updateTrackLists
();
...
...
@@ -1967,18 +1938,33 @@ public class StyledPlayerControlView extends FrameLayout {
}
}
private
class
SubSettings
Adapter
extends
RecyclerView
.
Adapter
<
SubSettingViewHolder
>
{
private
final
class
PlaybackSpeed
Adapter
extends
RecyclerView
.
Adapter
<
SubSettingViewHolder
>
{
private
String
[]
texts
;
private
final
String
[]
playbackSpeedTexts
;
private
final
int
[]
playbackSpeedsMultBy100
;
private
int
selectedIndex
;
public
SubSettingsAdapter
()
{
texts
=
new
String
[
0
];
public
PlaybackSpeedAdapter
(
String
[]
playbackSpeedTexts
,
int
[]
playbackSpeedsMultBy100
)
{
this
.
playbackSpeedTexts
=
playbackSpeedTexts
;
this
.
playbackSpeedsMultBy100
=
playbackSpeedsMultBy100
;
}
public
void
updateSelectedIndex
(
float
playbackSpeed
)
{
int
currentSpeedMultBy100
=
Math
.
round
(
playbackSpeed
*
100
);
int
closestMatchIndex
=
0
;
int
closestMatchDifference
=
Integer
.
MAX_VALUE
;
for
(
int
i
=
0
;
i
<
playbackSpeedsMultBy100
.
length
;
i
++)
{
int
difference
=
Math
.
abs
(
currentSpeedMultBy100
-
playbackSpeedsMultBy100
[
i
]);
if
(
difference
<
closestMatchDifference
)
{
closestMatchIndex
=
i
;
closestMatchDifference
=
difference
;
}
}
selectedIndex
=
closestMatchIndex
;
}
public
void
init
(
String
[]
texts
,
int
selectedIndex
)
{
this
.
texts
=
texts
;
this
.
selectedIndex
=
selectedIndex
;
public
String
getSelectedText
()
{
return
playbackSpeedTexts
[
selectedIndex
];
}
@Override
...
...
@@ -1991,27 +1977,23 @@ public class StyledPlayerControlView extends FrameLayout {
@Override
public
void
onBindViewHolder
(
SubSettingViewHolder
holder
,
int
position
)
{
if
(
position
<
t
exts
.
length
)
{
holder
.
textView
.
setText
(
t
exts
[
position
]);
if
(
position
<
playbackSpeedT
exts
.
length
)
{
holder
.
textView
.
setText
(
playbackSpeedT
exts
[
position
]);
}
holder
.
checkView
.
setVisibility
(
position
==
selectedIndex
?
VISIBLE
:
INVISIBLE
);
holder
.
itemView
.
setOnClickListener
(
v
->
{
if
(
position
!=
selectedIndex
)
{
float
speed
=
playbackSpeedsMultBy100
[
position
]
/
100.0f
;
setPlaybackSpeed
(
speed
);
}
settingsWindow
.
dismiss
();
});
}
@Override
public
int
getItemCount
()
{
return
texts
.
length
;
}
}
private
final
class
SubSettingViewHolder
extends
RecyclerView
.
ViewHolder
{
private
final
TextView
textView
;
private
final
View
checkView
;
public
SubSettingViewHolder
(
View
itemView
)
{
super
(
itemView
);
textView
=
itemView
.
findViewById
(
R
.
id
.
exo_text
);
checkView
=
itemView
.
findViewById
(
R
.
id
.
exo_check
);
itemView
.
setOnClickListener
(
v
->
onSubSettingViewClicked
(
getAdapterPosition
()));
return
playbackSpeedTexts
.
length
;
}
}
...
...
@@ -2059,7 +2041,7 @@ public class StyledPlayerControlView extends FrameLayout {
}
@Override
public
void
onBindViewHolderAtZeroPosition
(
TrackSelection
ViewHolder
holder
)
{
public
void
onBindViewHolderAtZeroPosition
(
SubSetting
ViewHolder
holder
)
{
// CC options include "Off" at the first position, which disables text rendering.
holder
.
textView
.
setText
(
R
.
string
.
exo_track_selection_none
);
boolean
isTrackSelectionOff
=
true
;
...
...
@@ -2088,7 +2070,7 @@ public class StyledPlayerControlView extends FrameLayout {
}
@Override
public
void
onBindViewHolder
(
TrackSelection
ViewHolder
holder
,
int
position
)
{
public
void
onBindViewHolder
(
SubSetting
ViewHolder
holder
,
int
position
)
{
super
.
onBindViewHolder
(
holder
,
position
);
if
(
position
>
0
)
{
TrackInfo
track
=
tracks
.
get
(
position
-
1
);
...
...
@@ -2105,7 +2087,7 @@ public class StyledPlayerControlView extends FrameLayout {
private
final
class
AudioTrackSelectionAdapter
extends
TrackSelectionAdapter
{
@Override
public
void
onBindViewHolderAtZeroPosition
(
TrackSelection
ViewHolder
holder
)
{
public
void
onBindViewHolderAtZeroPosition
(
SubSetting
ViewHolder
holder
)
{
// Audio track selection option includes "Auto" at the top.
holder
.
textView
.
setText
(
R
.
string
.
exo_track_selection_auto
);
// hasSelectionOverride is true means there is an explicit track selection, not "Auto".
...
...
@@ -2184,8 +2166,7 @@ public class StyledPlayerControlView extends FrameLayout {
}
}
private
abstract
class
TrackSelectionAdapter
extends
RecyclerView
.
Adapter
<
TrackSelectionViewHolder
>
{
private
abstract
class
TrackSelectionAdapter
extends
RecyclerView
.
Adapter
<
SubSettingViewHolder
>
{
protected
List
<
Integer
>
rendererIndices
;
protected
List
<
TrackInfo
>
tracks
;
...
...
@@ -2201,19 +2182,19 @@ public class StyledPlayerControlView extends FrameLayout {
List
<
Integer
>
rendererIndices
,
List
<
TrackInfo
>
trackInfos
,
MappedTrackInfo
mappedTrackInfo
);
@Override
public
TrackSelection
ViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
public
SubSetting
ViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
View
v
=
LayoutInflater
.
from
(
getContext
())
.
inflate
(
R
.
layout
.
exo_styled_sub_settings_list_item
,
null
);
return
new
TrackSelection
ViewHolder
(
v
);
return
new
SubSetting
ViewHolder
(
v
);
}
public
abstract
void
onBindViewHolderAtZeroPosition
(
TrackSelection
ViewHolder
holder
);
public
abstract
void
onBindViewHolderAtZeroPosition
(
SubSetting
ViewHolder
holder
);
public
abstract
void
onTrackSelection
(
String
subtext
);
@Override
public
void
onBindViewHolder
(
TrackSelection
ViewHolder
holder
,
int
position
)
{
public
void
onBindViewHolder
(
SubSetting
ViewHolder
holder
,
int
position
)
{
if
(
trackSelector
==
null
||
mappedTrackInfo
==
null
)
{
return
;
}
...
...
@@ -2269,12 +2250,12 @@ public class StyledPlayerControlView extends FrameLayout {
}
}
private
static
class
TrackSelection
ViewHolder
extends
RecyclerView
.
ViewHolder
{
private
static
class
SubSetting
ViewHolder
extends
RecyclerView
.
ViewHolder
{
public
final
TextView
textView
;
public
final
View
checkView
;
public
TrackSelection
ViewHolder
(
View
itemView
)
{
public
SubSetting
ViewHolder
(
View
itemView
)
{
super
(
itemView
);
textView
=
itemView
.
findViewById
(
R
.
id
.
exo_text
);
checkView
=
itemView
.
findViewById
(
R
.
id
.
exo_check
);
...
...
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