example_ui_control.xml

Overview

This XML layout file defines the user interface for a custom media controller component, typically used in an Android application to control video playback. The layout is designed using Android Data Binding and consists primarily of playback control buttons (Rewind, Play/Pause, Fast Forward) and a SeekBar to display and control the video playback progress.

The file binds UI elements to a `UserController` object, allowing dynamic interaction between the UI and the underlying video playback logic, such as updating the SeekBar's progress based on the current playback time and adjusting its maximum value according to video duration.

This file is intended to be included or inflated within an activity or fragment responsible for media playback, enabling user interaction with the video content through standard media control actions.


Detailed Explanation of Components

Data Binding Section

<data>
    <variable
        name="controller"
        type="com.tubitv.media.bindings.UserController" />
</data>

Root Layout: FrameLayout

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    ...
</FrameLayout>

Playback Control Buttons

Each button represents a key media control action with specific layout and tags:

  1. Rewind Button

<Button
    android:id="@+id/rewind"
    android:layout_width="100dp"
    android:layout_height="40dp"
    android:layout_gravity="center|left"
    android:tag="rewind"
    android:text="Rewind" />
  1. Play/Pause Button

<Button
    android:id="@+id/play_pause"
    android:layout_width="100dp"
    android:layout_height="40dp"
    android:layout_gravity="center"
    android:tag="play_pause"
    android:text="Play/Pause" />
  1. Fast Forward Button

<Button
    android:id="@+id/fastford"
    android:layout_width="100dp"
    android:layout_height="40dp"
    android:layout_gravity="center|right"
    android:tag="fastford"
    android:text="fastford" />

SeekBar for Playback Progress

<SeekBar
    android:id="@+id/view_tubi_controller_seek_bar"
    style="@style/TubiSeekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_margin="10dp"
    android:layout_marginBottom="40dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:max="@{(int)controller.videoDuration}"
    android:maxHeight="2dp"
    android:minHeight="2dp"
    android:paddingBottom="@dimen/view_tubi_controller_seek_bar_padding_vertical"
    android:paddingLeft="@dimen/view_tubi_controller_seek_bar_padding_horizontal"
    android:paddingRight="@dimen/view_tubi_controller_seek_bar_padding_horizontal"
    android:paddingTop="@dimen/view_tubi_controller_seek_bar_padding_vertical"
    android:progress="@{(int)controller.videoCurrentTime}" />

Implementation Details and Algorithms


Integration with the Application


Usage Example

Assuming usage in an Android Fragment with data binding and a `UserController`:

class VideoPlayerFragment : Fragment() {

    private lateinit var binding: ExampleUiControlBinding
    private val userController: UserController by viewModels()

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        binding = DataBindingUtil.inflate(inflater, R.layout.example_ui_control, container, false)
        binding.controller = userController
        binding.lifecycleOwner = viewLifecycleOwner

        binding.rewind.setOnClickListener { userController.rewind() }
        binding.playPause.setOnClickListener { userController.togglePlayPause() }
        binding.fastford.setOnClickListener { userController.fastForward() }

        binding.viewTubiControllerSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                if (fromUser) {
                    userController.seekTo(progress)
                }
            }
            override fun onStartTrackingTouch(seekBar: SeekBar?) {}
            override fun onStopTrackingTouch(seekBar: SeekBar?) {}
        })

        return binding.root
    }
}

Visual Diagram

classDiagram
    class example_ui_control {
        <<Layout>>
        +FrameLayout (root container)
        +Button rewind
        +Button play_pause
        +Button fastford
        +SeekBar view_tubi_controller_seek_bar
    }

    example_ui_control --> UserController : binds to

Summary

The `example_ui_control.xml` file provides a clean, data-bound Android layout for a video playback controller interface. It combines three key playback buttons and a progress SeekBar, all integrated with a `UserController` for managing video state. The structure promotes separation of concerns by delegating playback control logic to the controller class, while the UI remains declarative and responsive to state changes. This layout is a modular component that can be reused or extended within the broader media playback system.