Skip to content

Commit

Permalink
Wire up view for Playback speed controls
Browse files Browse the repository at this point in the history
Wires up the view component for playback speed controls, based on the
pattern used in various other action items.
  • Loading branch information
DavidFair committed Jan 2, 2022
1 parent 5788167 commit 060b561
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jellyfin.androidtv.ui.playback.overlay.action.ChapterAction;
import org.jellyfin.androidtv.ui.playback.overlay.action.ClosedCaptionsAction;
import org.jellyfin.androidtv.ui.playback.overlay.action.GuideAction;
import org.jellyfin.androidtv.ui.playback.overlay.action.PlaybackSpeedAction;
import org.jellyfin.androidtv.ui.playback.overlay.action.PreviousLiveTvChannelAction;
import org.jellyfin.androidtv.ui.playback.overlay.action.RecordAction;
import org.jellyfin.androidtv.ui.playback.overlay.action.SelectAudioAction;
Expand All @@ -48,6 +49,7 @@ public class CustomPlaybackTransportControlGlue extends PlaybackTransportControl
private PlaybackControlsRow.SkipNextAction skipNextAction;
private SelectAudioAction selectAudioAction;
private ClosedCaptionsAction closedCaptionsAction;
private PlaybackSpeedAction playbackSpeedAction;
private AdjustAudioDelayAction adjustAudioDelayAction;
private ZoomAction zoomAction;
private ChapterAction chapterAction;
Expand Down Expand Up @@ -173,6 +175,8 @@ private void initActions(Context context) {
selectAudioAction.setLabels(new String[]{context.getString(R.string.lbl_audio_track)});
closedCaptionsAction = new ClosedCaptionsAction(context, this);
closedCaptionsAction.setLabels(new String[]{context.getString(R.string.lbl_subtitle_track)});
playbackSpeedAction = new PlaybackSpeedAction(context, this);
playbackSpeedAction.setLabels(new String[]{context.getString(R.string.lbl_playback_speed)});
adjustAudioDelayAction = new AdjustAudioDelayAction(context, this);
adjustAudioDelayAction.setLabels(new String[]{context.getString(R.string.lbl_audio_delay)});
zoomAction = new ZoomAction(context, this);
Expand Down Expand Up @@ -219,6 +223,8 @@ void addMediaActions() {
primaryActionsAdapter.add(closedCaptionsAction);
}

primaryActionsAdapter.add(playbackSpeedAction);

if (hasMultiAudio()) {
primaryActionsAdapter.add(selectAudioAction);
}
Expand Down Expand Up @@ -282,6 +288,9 @@ public void onCustomActionClicked(Action action, View view) {
} else if (action == closedCaptionsAction) {
leanbackOverlayFragment.setFading(false);
closedCaptionsAction.handleClickAction(playbackController, leanbackOverlayFragment, getContext(), view);
} else if (action == playbackSpeedAction) {
leanbackOverlayFragment.setFading(false);
playbackSpeedAction.handleClickAction(playbackController, leanbackOverlayFragment, getContext(), view);
} else if (action == adjustAudioDelayAction) {
leanbackOverlayFragment.setFading(false);
adjustAudioDelayAction.handleClickAction(playbackController, leanbackOverlayFragment, getContext(), view);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.jellyfin.androidtv.ui.playback.overlay.action

import android.content.Context
import org.jellyfin.androidtv.ui.playback.overlay.CustomPlaybackTransportControlGlue
import org.jellyfin.androidtv.ui.playback.PlaybackController
import org.jellyfin.androidtv.ui.playback.overlay.LeanbackOverlayFragment
import android.view.Gravity
import android.view.MenuItem
import android.view.View
import android.widget.PopupMenu
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.ui.playback.VideoSpeedController

class PlaybackSpeedAction(
context: Context,
customPlaybackTransportControlGlue: CustomPlaybackTransportControlGlue
) : CustomAction(context, customPlaybackTransportControlGlue) {
private val speeds = VideoSpeedController.Companion.SpeedSteps.values()

init {
initializeWithIcon(R.drawable.exo_ic_speed)
}

override fun handleClickAction(
playbackController: PlaybackController,
leanbackOverlayFragment: LeanbackOverlayFragment,
context: Context, view: View
) {
val speedController = VideoSpeedController(playbackController)
val speedMenu = populateMenu(context, view, speedController)

speedMenu.setOnDismissListener { leanbackOverlayFragment.setFading(true) }

speedMenu.setOnMenuItemClickListener { menuItem ->
speedController.setNewSpeed(speeds[menuItem.itemId])
speedMenu.dismiss()
return@setOnMenuItemClickListener true
}

speedMenu.show()
}

private fun populateMenu(
context: Context,
view: View,
speedController: VideoSpeedController
): PopupMenu {
val speedMenu = PopupMenu(context, view, Gravity.END)
val menu = speedMenu.menu
speeds.forEachIndexed { i, speed ->
menu.add(0, i, i, String.format("%.2fx", speed.value))
}

menu.setGroupCheckable(0, true, true)
menu.getItem(speeds.indexOf(speedController.getCurrentSpeed())).isChecked = true
return speedMenu
}


}
3 changes: 2 additions & 1 deletion app/src/main/res/values-en-rGB/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<string name="lbl_Reset">Reset</string>
<string name="pref_button_remapping_description">Press any button on the TV remote to assign it</string>
<string name="pref_subtitle_track_button">Subtitle track button</string>
<string name="lbl_playback_speed">Playback Speed</string>
<string name="pref_audio_track_button">Audio track button</string>
<string name="pref_button_remapping_category">Button Remapping</string>
<string name="lbl_unknown_key">Unknown (%1s)</string>
Expand Down Expand Up @@ -453,4 +454,4 @@
<string name="lbl_stretch">Stretch</string>
<string name="lbl_auto_crop">Auto Crop</string>
<string name="lbl_community_rating">Community Rating</string>
</resources>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<string name="lbl_stretch">Stretch</string>
<string name="lbl_fit">Normal</string>
<string name="lbl_audio_track">Select audio track</string>
<string name="lbl_playback_speed">Playback Speed</string>
<string name="lbl_subtitle_track">Select subtitle track</string>
<string name="msg_external_path">This feature will only work if you have properly set up your library on the server with network paths or path substitution and the client you are using can directly access these locations over the network.</string>
<string name="btn_got_it">Got it</string>
Expand Down

0 comments on commit 060b561

Please sign in to comment.