This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BasicMediaPlayerAdapter(context: Context) : MediaPlayerAdapter(context) { | |
| val playlist = ArrayList<Movie>() | |
| var playlistPosition = 0 | |
| private set | |
| override fun next() = loadMovie((playlistPosition + 1).mod(playlist.size)) | |
| override fun previous() = loadMovie((playlistPosition - 1).mod(playlist.size)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BasicTransportControlsGlue( | |
| context: Context, | |
| playerAdapter: BasicMediaPlayerAdapter, | |
| ) : PlaybackTransportControlGlue<BasicMediaPlayerAdapter>(context, playerAdapter) { | |
| // Primary actions | |
| private val forwardAction = PlaybackControlsRow.FastForwardAction(context) | |
| private val rewindAction = PlaybackControlsRow.RewindAction(context) | |
| private val nextAction = PlaybackControlsRow.SkipNextAction(context) | |
| private val previousAction = PlaybackControlsRow.SkipPreviousAction(context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val currentMovie: Movie | |
| get() = playerAdapter.playlist[playerAdapter.playlistPosition] | |
| // Event when ready state for play changes. | |
| override fun onPreparedStateChanged() { | |
| super.onPreparedStateChanged() | |
| playWhenPrepared() | |
| updateMovieInfo(currentMovie) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun onKey(v: View?, keyCode: Int, event: KeyEvent): Boolean { | |
| if (host.isControlsOverlayVisible || event.repeatCount > 0) { | |
| return super.onKey(v, keyCode, event) | |
| } | |
| return when (keyCode) { | |
| KeyEvent.KEYCODE_DPAD_RIGHT -> if (event.action != KeyEvent.ACTION_DOWN) false else { | |
| onActionClicked(forwardAction) | |
| true | |
| } | |
| KeyEvent.KEYCODE_DPAD_LEFT -> if (event.action != KeyEvent.ACTION_DOWN) false else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PlaybackVideoFragment : VideoSupportFragment() { | |
| private lateinit var transportControlGlue: BasicTransportControlGlue | |
| private lateinit var fastForwardIndicatorView: View | |
| private lateinit var rewindIndicatorView: View | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| val movies = activity?.intent?.getParcelableArrayListExtra(EXTRA_MOVIES) ?: emptyList<Movie>() | |
| transportControlGlue = BasicTransportControlGlue( | |
| context = requireContext(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| setOnKeyInterceptListener { view, keyCode, event -> | |
| if (isControlsOverlayVisible || event.repeatCount > 0) { | |
| isShowOrHideControlsOverlayOnUserInteraction = true | |
| } else when (keyCode) { | |
| KeyEvent.KEYCODE_DPAD_RIGHT -> { | |
| isShowOrHideControlsOverlayOnUserInteraction = event.action != KeyEvent.ACTION_DOWN | |
| if (event.action == KeyEvent.ACTION_DOWN) { | |
| animateIndicator(fastForwardIndicatorView) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun animateIndicator(indicatorView: View) { | |
| indicatorView.animate() | |
| .withEndAction { | |
| indicatorView.isVisible = false | |
| indicatorView.alpha = 1F | |
| indicatorView.scaleX = 1F | |
| indicatorView.scaleY = 1F | |
| } | |
| .withStartAction { | |
| indicatorView.isVisible = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Glide.with(context) | |
| .asBitmap() | |
| .load(movie.cardImageUrl) | |
| .into(object : CustomTarget<Bitmap>() { | |
| override fun onResourceReady(bitmap: Bitmap, t: Transition<in Bitmap>?) { | |
| controlsRow.setImageBitmap(context, bitmap) | |
| host.notifyPlaybackRowChanged() | |
| } | |
| override fun onLoadCleared(placeholder: Drawable?) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private val thumbsUpAction = PlaybackControlsRow.ThumbsUpAction(context).apply { | |
| index = PlaybackControlsRow.ThumbsUpAction.INDEX_OUTLINE | |
| } | |
| private val shuffleAction = PlaybackControlsRow.ShuffleAction(context) | |
| private val repeatAction = PlaybackControlsRow.RepeatAction(context) | |
| private val myListAction = MyListAction(context) | |
| override fun onCreateSecondaryActions(secondaryActionsAdapter: ArrayObjectAdapter) { | |
| secondaryActionsAdapter.add(thumbsUpAction) | |
| secondaryActionsAdapter.add(shuffleAction) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyListAction(context: Context) : MultiAction(R.id.tv_my_list_action) { | |
| init { | |
| val drawables = arrayOf( | |
| context.getDrawable(R.drawable.playback_controls_my_list_add), | |
| context.getDrawable(R.drawable.playback_controls_my_list_remove), | |
| ) | |
| setDrawables(drawables) | |
| val labels = arrayOf( | |
| context.getString(R.string.playback_controls_my_list_add), | |
| context.getString(R.string.playback_controls_my_list_remove), |
OlderNewer