Class PlayerControllerView

All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, View.OnClickListener, ViewManager, ViewParent, SeekBar.OnSeekBarChangeListener

public class PlayerControllerView extends LinearLayout implements View.OnClickListener, SeekBar.OnSeekBarChangeListener
This view component can be bound to a PlayerController to show controls.

The implementation can be customized without extending the class up to a certain degree using either view parameters or methods on the instance.

The following attributes are supported through XML in your layout files:

  • controller_layout_id - Specifies the id of the layout to be inflated. See below for more details.
  • skip_increase_ms - Specifies time in milliseconds that the player should skip forward when the skip forward button is pressed
  • skip_increase_ms - Specifies time in milliseconds that the player should skip backward when the skip back button is pressed
  • auto_hide - Specifies if the controller should be hidden automatically.
  • toggle_visibility - Specify if visibility should be toggled when the root view is touched multiple times.
    • Note that this used the DefaultVisibilityController. If you set a custom visibility controller, this might not apply
    • You need to bind a IPlayerView to register the touch events successfully.
    • Default: true
  • auto_hide_delay - Specify the delay in milliseconds if auto hiding is enabled.
  • animation_enabled - Specify if default hide and show animations are enabled
  • animation_duration - Specify if default duration for hide and show animations
  • animation_view_position - Specify the controls position relative to the parent. Current top and bottom are supported. This defined on which direction the default animation will run.

Overriding the default layout

The view, by default loads its corresponding layout definition from res/layout/cl_player_controller_view.xml. If you create such file in you own app, this will effectively override the default layout definition.

Alternatively, you can always use the controller_layout_id parameter and reference a custom layout when you add this view.

When the view initializes its components, we are looking for specific ids in the layout file. All of the components are optional, but if you want to make sure the the default behaviour is enabled, please use the corresponding ids to identify the components in you layout:

  • presto_play_pause_button - The play/pause toggle button. Please note that the default implementation uses state lists on the views "selected" state to change the image icon that will be used.
  • presto_rewind_button - The rewind button.
  • presto_fastforward_button - The fast-forward button.
  • presto_skip_back_button - The skip backwards button
  • presto_skip_forward_button - The skip backwards button
  • presto_next_button - Select next item button
    • Type: View
    • Note: There is not default binding logic in place for this button and you need to register your own click listener
  • presto_previous_button - Select next item button
    • Type: View
    • Note: There is not default binding logic in place for this button and you need to register your own click listener
  • presto_select_scale_button - The scale selection button.
  • presto_select_audio_button - The audio or language selection button.
  • presto_select_subtitle_button - The subtitle selection button.
  • presto_select_video_button - The video quality selection button.
  • presto_current_time - Text view that shows the current playback position
  • presto_total_time - Text view that shows the total duration or the "live" indicator
  • presto_playback_speed_text - Text view that shows the playback speed when fast-forward playback is active
  • presto_seek_bar - The scrubbing seek bar

Using custom layout files

Setting the controller_layout_id attribute on a PlayerControllerView allows you to selectively change the layout resource that will be used by this component. This can be used for example if you do not want to overwrite the default or you need to apply a different layout per instance.

Selection Dialogs

If you bind this view not only to a PlayerController but also to a IPlayerView using bind(IPlayerView) or bind(PlayerController, IPlayerView, Playlist), default track and scale selection dialogs are available. You can sub-class this view to overwrite the dialog displays and customize the way the selection will be presented to the user. For this, you should overwrite showAudioSelection(), showVideoQualitySelection(), showSubtitleSelection(), and showScaleSelection() respectively.

If you would like to go with the default dialogs, you can customize the label rendering for each of the dialog by setting a Converter that will be used to create the textual representation for the items that can be selected. The default dialogs use the tracks label.

Subtitle Track selection

You can use setSubtitleTrackConverter(Converter) to create labels for subtitle tracks. By default, the selection dialog will use the R.string.presto_controls_subtitle_selection_dialog_title string reference to set the Dialog title. You can use the same string ID to overwrite the default title.

Video Track selection

You can use setVideoTrackConverter(Converter) to create labels for video tracks. By default, the selection dialog will use the R.string.presto_controls_quality_selection_dialog_title string reference to set the Dialog title. You can use the same string ID to overwrite the default title.

Audio Track selection

You can use setAudioTrackConverter(Converter) to create labels for audio tracks. By default, the selection dialog will use the R.string.presto_controls_language_selection_dialog_title string reference to set the Dialog title. You can use the same string ID to overwrite the default title.

Scaling Mode selection

You can use setScalingModeConverter(Converter) to create labels for scaling modes. By default, the selection dialog will use the R.string.presto_controls_scaling_selection_dialog_title string reference to set the Dialog title. You can use the same string ID to overwrite the default title.

Visibility controls

The view exposes a default VisibilityController that is used to hide the controls for example when Advertisements are played. You can set your own controller using setVisibilityController(VisibilityController). Take a look at the DefaultVisibilityController, it provides the ability to add touch events to toggle controls and can be used to add simple animation to show and hide the controls view.
Since:
4.0.0
  • Constructor Details

    • PlayerControllerView

      public PlayerControllerView(Context context)
    • PlayerControllerView

      public PlayerControllerView(Context context, AttributeSet attrs)
    • PlayerControllerView

      public PlayerControllerView(Context context, AttributeSet attrs, int defStyleAttr)
  • Method Details

    • showControlsAndFocus

      public void showControlsAndFocus(boolean userInteraction)
      Shows player controls. Focus is set to the play/pause button.
      Parameters:
      userInteraction - Indicates that the call was due to a user interaction
    • addListener

      public void addListener(PlayerControllerView.Listener listener)
      Add a new listener.
      Parameters:
      listener - The listener
    • removeListener

      public void removeListener(PlayerControllerView.Listener listener)
      Remove a listener.
      Parameters:
      listener - The listener
    • setVisibility

      public void setVisibility(int visibility)
      Overrides:
      setVisibility in class View
    • setControllerLayoutId

      public void setControllerLayoutId(@LayoutRes int controllerLayoutId)
      Sets the layout resource and re-initializes the view with that layout resource. The component expects the ID's listed in the documentation to be available on the given layout.

      Note that you need to call this method before you bind a PlayerController to this view!

      Parameters:
      controllerLayoutId - The layout ID
    • setSkipIncreaseMs

      public void setSkipIncreaseMs(int increaseMs)
      Set the amount of time in milliseconds that player should skip forward when the skip forward button is pressed.
      Parameters:
      increaseMs - Time in MS
    • setSkipDecreaseMs

      public void setSkipDecreaseMs(int decreaseMs)
      ASet the amount of time in milliseconds that the player should skip backward when the skip back button is pressed.
      Parameters:
      decreaseMs - Time in MS
    • setSubtitleTrackConverter

      public void setSubtitleTrackConverter(@NonNull Converter<SubtitleTrack,String> subtitleTrackConverter)
      Set the converter that will be used to create textual representations for subtitle tracks.
      Parameters:
      subtitleTrackConverter - The converter
    • setVideoTrackConverter

      public void setVideoTrackConverter(@NonNull Converter<VideoTrackQuality,String> videoTrackConverter)
      Set the converter that will be used to create textual representations for video tracks.
      Parameters:
      videoTrackConverter - The video track converter
    • setAudioTrackConverter

      public void setAudioTrackConverter(Converter<AudioTrack,String> audioTrackConverter)
      Set the converter that will be used to create textual representations for audio tracks.
      Parameters:
      audioTrackConverter - The audio track converter
    • setScalingModeConverter

      public void setScalingModeConverter(Converter<Integer,String> scalingModeConverter)
      Set the converter that will be used to create textual representation of scaling modes.
      Parameters:
      scalingModeConverter - The scaling mode converter
    • showExtendedTrackInfo

      public void showExtendedTrackInfo(boolean showExtendedTrackInfo)
      If the default convert are used for selection dialogs, this can be enabled to render additional track information such as bitrate information or codec information into the track label. This is usually used only for debugging purposes!
      Parameters:
      showExtendedTrackInfo - Enable rendering of additional track information
    • setAnimateSubtitleMargins

      public void setAnimateSubtitleMargins(boolean animateSubtitleMargins)
      Enable or disable subtitles margins animation, default is disabled
      Parameters:
      animateSubtitleMargins - True to animate otherwise false
    • getVisibilityController

      public VisibilityController getVisibilityController()
      Returns the current visibility controller
      Returns:
      The visibility controller
    • setVisibilityController

      public void setVisibilityController(@NonNull VisibilityController visibilityController)
      Set the visibility controller that will be used to show or hide this control view.
      Parameters:
      visibilityController - The visibility controller
    • setSeekBarListener

      public void setSeekBarListener(@Nullable PlayerControllerView.SeekBarListener seekBarListener)
      Set the seek bar listener that can be used to receive callbacks when the user interacts with the seekbar.
      Parameters:
      seekBarListener - The listener
    • bind

      public void bind(@NonNull IPlayerView playerView)
      Binds the controls to the given player view and the controller that is exposed by the view. In case the PlayerController attached to the IPlayerView implements the Playlist then it is also used as the Playlist controller
      Parameters:
      playerView - The player view
    • bind

      public void bind(@NonNull IPlayerView playerView, @NonNull Playlist playlist)
    • bind

      public void bind(@NonNull PlayerController playerController)
      Binds the controls to the given player controller. NOTE that this will permit the default dialogs to work properly since they require a player view to to bound as well. In case the PlayerController implements the Playlist then it is also used as the Playlist controller
      Parameters:
      playerController - The player controller
    • bind

      public void bind(@NonNull PlayerController playerController, @Nullable IPlayerView playerView, @Nullable Playlist playlist)
      Binds the controls view to the given player controller and the the optional player view. The player view is not mandatory but is required to show the default track selection dialogs.
      Parameters:
      playerController - The player controller
      playerView - The player view
    • unbind

      public void unbind()
      Unbinds the controls and the view from this controller and resets all attached listeners. Please note that if you are calling this method, you will need to bind this controller again and also attach any custom listeners such as the PlayerControllerView.SeekBarListener.
    • setEnabled

      public void setEnabled(boolean enabled)
      Overrides:
      setEnabled in class View
    • dispatchKeyEvent

      public boolean dispatchKeyEvent(KeyEvent event)
      Overrides:
      dispatchKeyEvent in class ViewGroup
    • dispatchMediaKeyEvent

      public boolean dispatchMediaKeyEvent(KeyEvent event)
      Handles key event for the default keys implemented by this component.
      Parameters:
      event - The key event
      Returns:
      True if the event was handled by this method
    • onClick

      public void onClick(View v)
      Specified by:
      onClick in interface View.OnClickListener
    • setTranslationY

      public void setTranslationY(float translationY)
      Overrides:
      setTranslationY in class View
    • showSubtitleSelection

      public void showSubtitleSelection()
    • showVideoQualitySelection

      public void showVideoQualitySelection()
    • showAudioSelection

      public void showAudioSelection()
    • showScaleSelection

      public void showScaleSelection()
    • onProgressChanged

      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
      Specified by:
      onProgressChanged in interface SeekBar.OnSeekBarChangeListener
    • onStartTrackingTouch

      public void onStartTrackingTouch(SeekBar seekBar)
      Specified by:
      onStartTrackingTouch in interface SeekBar.OnSeekBarChangeListener
    • onStopTrackingTouch

      public void onStopTrackingTouch(SeekBar seekBar)
      Specified by:
      onStopTrackingTouch in interface SeekBar.OnSeekBarChangeListener
    • find

      public View find(int id)