mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Remove custom speed from StyledPlayerControlView
Real apps probably aren't going to be allowing playback speed to be set to anything other than the options listed in their UI, and so this is not worth the complexity. It also violates the idea that the UI should look the same regardless of when the player is set on the view, since if it's set and then the playback speed is changed to a listed option then the custom speed remains, where-as if the speed is changed to a listed option and then it's set, the custom speed will not be shown. PiperOrigin-RevId: 343260450
This commit is contained in:
parent
cc665f994c
commit
2714fb0241
1 changed files with 36 additions and 47 deletions
|
|
@ -352,7 +352,6 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
|
|
||||||
private static final int SETTINGS_PLAYBACK_SPEED_POSITION = 0;
|
private static final int SETTINGS_PLAYBACK_SPEED_POSITION = 0;
|
||||||
private static final int SETTINGS_AUDIO_TRACK_SELECTION_POSITION = 1;
|
private static final int SETTINGS_AUDIO_TRACK_SELECTION_POSITION = 1;
|
||||||
private static final int UNDEFINED_POSITION = -1;
|
|
||||||
|
|
||||||
private final ComponentListener componentListener;
|
private final ComponentListener componentListener;
|
||||||
private final CopyOnWriteArrayList<VisibilityListener> visibilityListeners;
|
private final CopyOnWriteArrayList<VisibilityListener> visibilityListeners;
|
||||||
|
|
@ -427,9 +426,8 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
private SettingsAdapter settingsAdapter;
|
private SettingsAdapter settingsAdapter;
|
||||||
private SubSettingsAdapter subSettingsAdapter;
|
private SubSettingsAdapter subSettingsAdapter;
|
||||||
private PopupWindow settingsWindow;
|
private PopupWindow settingsWindow;
|
||||||
private List<String> playbackSpeedTextList;
|
private String[] playbackSpeedTexts;
|
||||||
private List<Integer> playbackSpeedMultBy100List;
|
private int[] playbackSpeedsMultBy100;
|
||||||
private int customPlaybackSpeedIndex;
|
|
||||||
private int selectedPlaybackSpeedIndex;
|
private int selectedPlaybackSpeedIndex;
|
||||||
private boolean needToHideBars;
|
private boolean needToHideBars;
|
||||||
private int settingsWindowMargin;
|
private int settingsWindowMargin;
|
||||||
|
|
@ -653,19 +651,11 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
resources.getDrawable(R.drawable.exo_styled_controls_audiotrack);
|
resources.getDrawable(R.drawable.exo_styled_controls_audiotrack);
|
||||||
settingsAdapter = new SettingsAdapter(settingTexts, settingIcons);
|
settingsAdapter = new SettingsAdapter(settingTexts, settingIcons);
|
||||||
|
|
||||||
playbackSpeedTextList =
|
playbackSpeedTexts = resources.getStringArray(R.array.exo_playback_speeds);
|
||||||
new ArrayList<>(Arrays.asList(resources.getStringArray(R.array.exo_playback_speeds)));
|
playbackSpeedsMultBy100 = resources.getIntArray(R.array.exo_speed_multiplied_by_100);
|
||||||
playbackSpeedMultBy100List = new ArrayList<>();
|
|
||||||
int[] speeds = resources.getIntArray(R.array.exo_speed_multiplied_by_100);
|
|
||||||
for (int speed : speeds) {
|
|
||||||
playbackSpeedMultBy100List.add(speed);
|
|
||||||
}
|
|
||||||
selectedPlaybackSpeedIndex = playbackSpeedMultBy100List.indexOf(100);
|
|
||||||
customPlaybackSpeedIndex = UNDEFINED_POSITION;
|
|
||||||
settingsWindowMargin = resources.getDimensionPixelSize(R.dimen.exo_settings_offset);
|
settingsWindowMargin = resources.getDimensionPixelSize(R.dimen.exo_settings_offset);
|
||||||
|
|
||||||
subSettingsAdapter = new SubSettingsAdapter();
|
subSettingsAdapter = new SubSettingsAdapter();
|
||||||
subSettingsAdapter.setCheckPosition(UNDEFINED_POSITION);
|
|
||||||
settingsView =
|
settingsView =
|
||||||
(RecyclerView)
|
(RecyclerView)
|
||||||
LayoutInflater.from(context).inflate(R.layout.exo_styled_settings_list, null);
|
LayoutInflater.from(context).inflate(R.layout.exo_styled_settings_list, null);
|
||||||
|
|
@ -1445,25 +1435,18 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
}
|
}
|
||||||
float speed = player.getPlaybackParameters().speed;
|
float speed = player.getPlaybackParameters().speed;
|
||||||
int currentSpeedMultBy100 = Math.round(speed * 100);
|
int currentSpeedMultBy100 = Math.round(speed * 100);
|
||||||
int indexForCurrentSpeed = playbackSpeedMultBy100List.indexOf(currentSpeedMultBy100);
|
int closestMatchIndex = 0;
|
||||||
if (indexForCurrentSpeed == UNDEFINED_POSITION) {
|
int closestMatchDifference = Integer.MAX_VALUE;
|
||||||
if (customPlaybackSpeedIndex != UNDEFINED_POSITION) {
|
for (int i = 0; i < playbackSpeedsMultBy100.length; i++) {
|
||||||
playbackSpeedMultBy100List.remove(customPlaybackSpeedIndex);
|
int difference = Math.abs(currentSpeedMultBy100 - playbackSpeedsMultBy100[i]);
|
||||||
playbackSpeedTextList.remove(customPlaybackSpeedIndex);
|
if (difference < closestMatchDifference) {
|
||||||
customPlaybackSpeedIndex = UNDEFINED_POSITION;
|
closestMatchIndex = i;
|
||||||
|
closestMatchDifference = difference;
|
||||||
}
|
}
|
||||||
indexForCurrentSpeed =
|
|
||||||
-Collections.binarySearch(playbackSpeedMultBy100List, currentSpeedMultBy100) - 1;
|
|
||||||
String customSpeedText =
|
|
||||||
resources.getString(R.string.exo_controls_custom_playback_speed, speed);
|
|
||||||
playbackSpeedMultBy100List.add(indexForCurrentSpeed, currentSpeedMultBy100);
|
|
||||||
playbackSpeedTextList.add(indexForCurrentSpeed, customSpeedText);
|
|
||||||
customPlaybackSpeedIndex = indexForCurrentSpeed;
|
|
||||||
}
|
}
|
||||||
|
selectedPlaybackSpeedIndex = closestMatchIndex;
|
||||||
selectedPlaybackSpeedIndex = indexForCurrentSpeed;
|
|
||||||
settingsAdapter.setSubTextAtPosition(
|
settingsAdapter.setSubTextAtPosition(
|
||||||
SETTINGS_PLAYBACK_SPEED_POSITION, playbackSpeedTextList.get(indexForCurrentSpeed));
|
SETTINGS_PLAYBACK_SPEED_POSITION, playbackSpeedTexts[closestMatchIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSettingsWindowSize() {
|
private void updateSettingsWindowSize() {
|
||||||
|
|
@ -1570,8 +1553,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
|
|
||||||
private void onSettingViewClicked(int position) {
|
private void onSettingViewClicked(int position) {
|
||||||
if (position == SETTINGS_PLAYBACK_SPEED_POSITION) {
|
if (position == SETTINGS_PLAYBACK_SPEED_POSITION) {
|
||||||
subSettingsAdapter.setTexts(playbackSpeedTextList);
|
subSettingsAdapter.init(playbackSpeedTexts, selectedPlaybackSpeedIndex);
|
||||||
subSettingsAdapter.setCheckPosition(selectedPlaybackSpeedIndex);
|
|
||||||
selectedMainSettingsPosition = SETTINGS_PLAYBACK_SPEED_POSITION;
|
selectedMainSettingsPosition = SETTINGS_PLAYBACK_SPEED_POSITION;
|
||||||
displaySettingsWindow(subSettingsAdapter);
|
displaySettingsWindow(subSettingsAdapter);
|
||||||
} else if (position == SETTINGS_AUDIO_TRACK_SELECTION_POSITION) {
|
} else if (position == SETTINGS_AUDIO_TRACK_SELECTION_POSITION) {
|
||||||
|
|
@ -1585,7 +1567,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
private void onSubSettingViewClicked(int position) {
|
private void onSubSettingViewClicked(int position) {
|
||||||
if (selectedMainSettingsPosition == SETTINGS_PLAYBACK_SPEED_POSITION) {
|
if (selectedMainSettingsPosition == SETTINGS_PLAYBACK_SPEED_POSITION) {
|
||||||
if (position != selectedPlaybackSpeedIndex) {
|
if (position != selectedPlaybackSpeedIndex) {
|
||||||
float speed = playbackSpeedMultBy100List.get(position) / 100.0f;
|
float speed = playbackSpeedsMultBy100[position] / 100.0f;
|
||||||
setPlaybackSpeed(speed);
|
setPlaybackSpeed(speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1878,6 +1860,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder> {
|
private class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder> {
|
||||||
|
|
||||||
private final String[] mainTexts;
|
private final String[] mainTexts;
|
||||||
private final String[] subTexts;
|
private final String[] subTexts;
|
||||||
private final Drawable[] iconIds;
|
private final Drawable[] iconIds;
|
||||||
|
|
@ -1928,6 +1911,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class SettingViewHolder extends RecyclerView.ViewHolder {
|
private final class SettingViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private final TextView mainTextView;
|
private final TextView mainTextView;
|
||||||
private final TextView subTextView;
|
private final TextView subTextView;
|
||||||
private final ImageView iconView;
|
private final ImageView iconView;
|
||||||
|
|
@ -1942,8 +1926,18 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SubSettingsAdapter extends RecyclerView.Adapter<SubSettingViewHolder> {
|
private class SubSettingsAdapter extends RecyclerView.Adapter<SubSettingViewHolder> {
|
||||||
@Nullable private List<String> texts;
|
|
||||||
private int checkPosition;
|
private String[] texts;
|
||||||
|
private int selectedIndex;
|
||||||
|
|
||||||
|
public SubSettingsAdapter() {
|
||||||
|
texts = new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(String[] texts, int selectedIndex) {
|
||||||
|
this.texts = texts;
|
||||||
|
this.selectedIndex = selectedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SubSettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public SubSettingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
|
@ -1955,23 +1949,15 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(SubSettingViewHolder holder, int position) {
|
public void onBindViewHolder(SubSettingViewHolder holder, int position) {
|
||||||
if (texts != null) {
|
if (position < texts.length) {
|
||||||
holder.textView.setText(texts.get(position));
|
holder.textView.setText(texts[position]);
|
||||||
}
|
}
|
||||||
holder.checkView.setVisibility(position == checkPosition ? VISIBLE : INVISIBLE);
|
holder.checkView.setVisibility(position == selectedIndex ? VISIBLE : INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return texts != null ? texts.size() : 0;
|
return texts.length;
|
||||||
}
|
|
||||||
|
|
||||||
public void setTexts(@Nullable List<String> texts) {
|
|
||||||
this.texts = texts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCheckPosition(int checkPosition) {
|
|
||||||
this.checkPosition = checkPosition;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1988,6 +1974,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TrackInfo {
|
private static final class TrackInfo {
|
||||||
|
|
||||||
public final int rendererIndex;
|
public final int rendererIndex;
|
||||||
public final int groupIndex;
|
public final int groupIndex;
|
||||||
public final int trackIndex;
|
public final int trackIndex;
|
||||||
|
|
@ -2157,6 +2144,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
|
|
||||||
private abstract class TrackSelectionAdapter
|
private abstract class TrackSelectionAdapter
|
||||||
extends RecyclerView.Adapter<TrackSelectionViewHolder> {
|
extends RecyclerView.Adapter<TrackSelectionViewHolder> {
|
||||||
|
|
||||||
protected List<Integer> rendererIndices;
|
protected List<Integer> rendererIndices;
|
||||||
protected List<TrackInfo> tracks;
|
protected List<TrackInfo> tracks;
|
||||||
protected @Nullable MappedTrackInfo mappedTrackInfo;
|
protected @Nullable MappedTrackInfo mappedTrackInfo;
|
||||||
|
|
@ -2240,6 +2228,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TrackSelectionViewHolder extends RecyclerView.ViewHolder {
|
private static class TrackSelectionViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
public final TextView textView;
|
public final TextView textView;
|
||||||
public final View checkView;
|
public final View checkView;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue