Polyv Help Center

Help Center

13.faq

Updated: 2025-12-30 14:33:59

1. How to Modify Playback Speed Options

To modify the playback speed options, you need to edit the following 3 files:

  1. polyv_controller_media_center_speed.xml (Landscape speed selection layout)
  2. polyv_controller_media_center_speed_portrait.xml (Portrait speed selection layout)
  3. PolyvPlayerMediaController.java (Media controller logic code)

The following example demonstrates how to add a 2.5x speed option:

Steps:

  1. Modify the landscape speed selection layout polyv_controller_media_center_speed.xml

    In the res/layout/polyv_controller_media_center_speed.xml file, locate the TextView list inside <LinearLayout> that displays the speed options. You need to add a new TextView between tv_speed20 and tv_speed30 to represent the 2.5x speed.

    Find the following code segment (or a similar location):

    
    


    **Insert the following code after `tv_speed20` and before `tv_speed30`:**

    ```xml
<TextView
    android:id="@+id/tv_speed20"
    style="@style/tv_click_controller_land_center"
    android:gravity="center"
    android:layout_weight="1"
    android:padding="@dimen/talk_common_margin"
    android:text="2x" />

<!-- 新增:2.5倍速选项 -->
<TextView
    android:id="@+id/tv_speed25"
    style="@style/tv_click_controller_land_center"
    android:gravity="center"
    android:layout_weight="1"
    android:padding="@dimen/talk_common_margin"
    android:text="2.5x" />

<TextView
    android:id="@+id/tv_speed30"
    style="@style/tv_click_controller_land_center"
    android:gravity="center"
    android:layout_weight="1"
    android:padding="@dimen/talk_common_margin"
    android:text="3x" />
  1. Modify the portrait speed selection layout polyv_controller_media_center_speed_portrait.xml

    In the res/layout/polyv_controller_media_center_speed_portrait.xml file, similarly add a new TextView between tv_speed20_portrait and tv_speed30_portrait.

    Find the following code segment (or a similar location):

    
    


    **Insert the following code after `tv_speed20_portrait` and before `tv_speed30_portrait`:**

    ```xml
<TextView
    android:id="@+id/tv_speed20_portrait"
    style="@style/tv_click_controller_portrait_center"
    android:layout_marginRight="@dimen/corners_common_l"
    android:padding="@dimen/talk_common_margin"
    android:text="2x" />

<!-- 新增:2.5倍速选项 (竖屏) -->
<TextView
    android:id="@+id/tv_speed25_portrait"
    style="@style/tv_click_controller_portrait_center"
    android:layout_marginRight="@dimen/corners_common_l"
    android:padding="@dimen/talk_common_margin"
    android:text="2.5x" />

<TextView
    android:id="@+id/tv_speed30_portrait"
    style="@style/tv_click_controller_portrait_center"
    android:padding="@dimen/talk_common_margin"
    android:text="3x" />
  1. Modify PolyvPlayerMediaController.java

    This file contains the core logic and requires several modifications.

    1. Declare new TextView variables: At the top of the PolyvPlayerMediaController class, find the TextView declarations related to speed, and add the newly defined tv_speed25_portrait and tv_speed25.

      Find similar code:

      
      

    // 竖屏的播放速度布局 // ... private TextView tv_speed05_portrait, tv_speed075_portrait, tv_speed10_portrait, tv_speed125_portrait, tv_speed15_portrait, tv_speed20_portrait, tv_speed30_portrait; // ... // 横屏的播放速度布局 // ... private TextView tv_speed05, tv_speed075, tv_speed10, tv_speed125, tv_speed15, tv_speed20, tv_speed30;

    
        **Modify to:**
    
        ```java
    // 竖屏的播放速度布局
    // ...
    private TextView tv_speed05_portrait, tv_speed075_portrait, tv_speed10_portrait, tv_speed125_portrait, tv_speed15_portrait, tv_speed20_portrait, tv_speed25_portrait, tv_speed30_portrait;
    // ...
    // 横屏的播放速度布局
    // ...
    private TextView tv_speed05, tv_speed075, tv_speed10, tv_speed125, tv_speed15, tv_speed20, tv_speed25, tv_speed30;
    
    1. Initialize the new TextView in the findIdAndNew() method: Find the findIdAndNew() method and associate the newly declared TextView variable with its view ID from the XML.

      Find similar code:

      
      

    // ... 竖屏的播放速度布局的view tv_speed20_portrait = (TextView) view.findViewById(R.id.tv_speed20_portrait); tv_speed30_portrait = (TextView) view.findViewById(R.id.tv_speed30_portrait); // ... 横屏的播放速度布局的view tv_speed20 = (TextView) view.findViewById(R.id.tv_speed20); tv_speed30 = (TextView) view.findViewById(R.id.tv_speed30);

    
        **Modify to:**
    
        ```java
    // ... 竖屏的播放速度布局的view
    tv_speed20_portrait = (TextView) view.findViewById(R.id.tv_speed20_portrait);
    tv_speed25_portrait = (TextView) view.findViewById(R.id.tv_speed25_portrait); // 新增
    tv_speed30_portrait = (TextView) view.findViewById(R.id.tv_speed30_portrait);
    // ... 横屏的播放速度布局的view
    tv_speed20 = (TextView) view.findViewById(R.id.tv_speed20);
    tv_speed25 = (TextView) view.findViewById(R.id.tv_speed25); // 新增
    tv_speed30 = (TextView) view.findViewById(R.id.tv_speed30);
    
    1. Set click listeners for the new TextView in the initView() method: Find the initView() method and set the OnClickListener for tv_speed25_portrait and tv_speed25.

      Find similar code:

      
      

    // ... tv_speed20_portrait.setOnClickListener(this); tv_speed30_portrait.setOnClickListener(this); // ... tv_speed20.setOnClickListener(this); tv_speed30.setOnClickListener(this); // ...

    
        **Modify to:**
    
        ```java
    // ...
    tv_speed20_portrait.setOnClickListener(this);
    tv_speed25_portrait.setOnClickListener(this); // 新增
    tv_speed30_portrait.setOnClickListener(this);
    // ...
    tv_speed20.setOnClickListener(this);
    tv_speed25.setOnClickListener(this); // 新增
    tv_speed30.setOnClickListener(this);
    // ...
    
    1. Update the selection state and display text for 2.5x speed in the initSpeedView(float speed) method: The initSpeedView method is responsible for updating the UI selection state of speed options and the text in the top/portrait display area based on the current playback speed.

      Find similar code:

      
      

    public void initSpeedView(float speed) { tv_speed05.setSelected(false); tv_speed05_portrait.setSelected(false); // ... 其他倍速的 setSelected(false) tv_speed20.setSelected(false); tv_speed20_portrait.setSelected(false); tv_speed30.setSelected(false); tv_speed30_portrait.setSelected(false); // ... if (speed == 2) { tv_speed20.setSelected(true); tv_speed20_portrait.setSelected(true); tv_speed.setText("2x"); tv_speed_portrait.setText("2x"); } if (speed == 3) { tv_speed30.setSelected(true); tv_speed30_portrait.setSelected(true); tv_speed.setText("3x"); tv_speed_portrait.setText("3x"); } }

    
        **Modify to:**
    
        ```java
    public void initSpeedView(float speed) {
        tv_speed05.setSelected(false);
        tv_speed05_portrait.setSelected(false);
        tv_speed075.setSelected(false);
        tv_speed075_portrait.setSelected(false);
        tv_speed10.setSelected(false);
        tv_speed10_portrait.setSelected(false);
        tv_speed125.setSelected(false);
        tv_speed125_portrait.setSelected(false);
        tv_speed15.setSelected(false);
        tv_speed15_portrait.setSelected(false);
        tv_speed20.setSelected(false);
        tv_speed20_portrait.setSelected(false);
        tv_speed25.setSelected(false); // 新增
        tv_speed25_portrait.setSelected(false); // 新增
        tv_speed30.setSelected(false);
        tv_speed30_portrait.setSelected(false);
        if (speed == 0.5) {
            tv_speed05.setSelected(true);
            tv_speed05_portrait.setSelected(true);
            tv_speed.setText("0.5x");
            tv_speed_portrait.setText("0.5x");
        }
        // ... 其他倍速的 if (speed == X) 块
        if (speed == 2) {
            tv_speed20.setSelected(true);
            tv_speed20_portrait.setSelected(true);
            tv_speed.setText("2x");
            tv_speed_portrait.setText("2x");
        }
        if (speed == 2.5) { // 新增
            tv_speed25.setSelected(true);
            tv_speed25_portrait.setSelected(true);
            tv_speed.setText("2.5x");
            tv_speed_portrait.setText("2.5x");
        }
        if (speed == 3) {
            tv_speed30.setSelected(true);
            tv_speed30_portrait.setSelected(true);
            tv_speed.setText("3x");
            tv_speed_portrait.setText("3x");
        }
    }
    
    1. Handle the click event for 2.5x speed in the onClick(View view) method: This method handles click events for all UI elements. You need to add a case to respond to clicks on the 2.5x speed option.

      Find similar code:

      
      

    case R.id.tv_speed20_portrait: case R.id.tv_speed20: resetSpeedView(2); break; case R.id.tv_speed30_portrait: case R.id.tv_speed30: resetSpeedView(3); break;

    
        **Modify to:**
    
        ```java
    case R.id.tv_speed20_portrait:
    case R.id.tv_speed20:
        resetSpeedView(2);
        break;
    case R.id.tv_speed25_portrait: // 新增
    case R.id.tv_speed25: // 新增
        resetSpeedView(2.5F); // 注意:浮点数需要F后缀
        break;
    case R.id.tv_speed30_portrait:
    case R.id.tv_speed30:
        resetSpeedView(3);
        break;
    

2. How to Convert a Demo to AndroidX

Android Studio has a built-in refactoring tool that can automatically scan Java/Kotlin code, XML layout files, and Gradle scripts in a project to batch replace old Support library references with AndroidX.

2.1 Migration Steps:

  1. Start Migration: Open the demo project, click Refactor > Migrate to AndroidX... in the top menu bar.
  2. Backup Project: In the popup dialog, it is strongly recommended to check Backup project as Zip file. Since the migration involves modifying the entire codebase, a backup prevents code corruption from unforeseen conversion errors.
  3. Analysis View: After clicking Migrate, Android Studio will list all files and locations to be modified in the Refactoring Preview window at the bottom.
  4. Execute Refactoring: After confirming the list is correct, click the Do Refactor button at the bottom to complete the conversion.

2.2 Software Version Requirements

Not all Android Studio versions support one-click migration. Ensure your development environment meets the following requirements:

  • Minimum Version Requirement: Android Studio 3.2 or higher.
    • Version 3.2 is the starting point where Google officially introduced the AndroidX migration tool.
    • Recommended Version: It is recommended to use Android Studio Dolphin (2021.3.1) or higher (e.g., Hedgehog, Iguana, etc.), as newer versions provide more stable support for Jetifier (third-party library conversion) and better handling of Gradle script conflicts.
    • Historical Version Archive: Android Studio Download Archives. If you cannot find the Migrate to AndroidX... feature in lower or higher versions, you can find the Android Studio Dolphin (2021.3.1) version here for installation.
联系客服,在线咨询