All Products
Search
Document Center

ApsaraVideo VOD:Flutter player with UI integration

Last Updated:Nov 25, 2025

This topic describes how to integrate the Flutter player with a user interface (UI). You can integrate AliPlayerWidget to quickly use the Flutter player.

Overview

AliPlayerWidget is a high-performance video playback component for Flutter applications. It is built on the ApsaraVideo Player software development kit (SDK) flutter_aliplayer. AliPlayerWidget supports video on demand (VOD), live streaming, list playback, and mini-dramas. It provides a rich set of features and highly flexible UI customization capabilities to meet video playback requirements in various fields, such as education, entertainment, e-commerce, and mini-drama applications.

Requirements

Category

Description

Flutter version

2.10.0 or later. We recommend that you use 3.22.2.

JDK version

Use JDK 11.

Note

To set the JDK version to 11, go to Preferences > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK and select 11. If version 11 is not available, upgrade your Android Studio.

Android version

Android 6.0 or later. Gradle 7.0 or later.

iOS version

iOS 10.0 or later.

Mobile phone chip

Architecture: armeabi-v7a or arm64-v8a.

Development tool

Use Android Studio or Visual Studio Code.

Permissions

Network permissions

  • Enable network permissions in Android and iOS to allow the player to load online video resources.

License configuration

  • You must obtain a license certificate and license key for the player from Apsara Video SDK. For more information, see Manage licenses.

Note

Note: If the license is not configured correctly, the player will not function and may throw a license authorization exception.

For more information about initialization configurations, see the aliplayer_widget_example sample project.

Demo

To help you quickly experience the features of AliPlayerWidget, we provide a demo package built on the aliplayer_widget_example sample project. You can install and run this demo on your device without any additional environment configuration.

How to obtain

Scan the following QR code with your mobile phone to download and install the demo package:

demo-qr-code

Note

Note: The QR code links to the latest version of the demo package. Make sure your device allows the installation of third-party applications.

Integrate and download the SDK

aliplayer_widget is open source and available for download. To customize the component, you can obtain and modify the source code. You can obtain the complete source code in one of the following ways:

Download method

Download link

Pub source

Note

We recommend that you integrate aliplayer_widget using a package management tool.

GitHub

GitHub repository

Source code package

aliplayer_widget.zip

The downloaded package includes:

  • Core components: The complete implementation of AliPlayerWidget and AliPlayerWidgetController.

  • Sample project: aliplayer_widget_example provides code samples for scenarios such as VOD, live streaming, and list playback to help you quickly integrate and use the component.

  • Documentation and comments: The source code includes detailed comments and development guides for custom development.

Integration

Add the dependency manually

Add the following dependency to your pubspec.yaml file:

dependencies:
  aliplayer_widget: ^x.y.z
Note

Note: x.y.z represents the version number of aliplayer_widget. You can view the latest stable version on the Pub.dev official page and replace x.y.z with the actual version number, such as ^7.0.0.

Use the command-line tool

If you prefer to use the command line, run the following command to add the dependency:

flutter pub add aliplayer_widget

This command automatically updates your pubspec.yaml file.

After you add the dependency, run the following command in the terminal to install it:

flutter pub get

After you complete these steps, AliPlayerWidget is integrated into your project. You can now start using it.

Quick start

Play a video

The following example shows how to embed a video player in a page. You can play a video with just a few lines of code.

Expand to view the sample code

import 'package:flutter/material.dart';
import 'package:aliplayer_widget/aliplayer_widget_lib.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: VideoPlayerPage(),
    );
  }
}

class VideoPlayerPage extends StatefulWidget {
  @override
  _VideoPlayerPageState createState() => _VideoPlayerPageState();
}

class _VideoPlayerPageState extends State<VideoPlayerPage> {
  late AliPlayerWidgetController _controller;

  @override
  void initState() {
    super.initState();
    // Initialize the player component controller.
    _controller = AliPlayerWidgetController(context);
    // Configure the player component data.
    final data = AliPlayerWidgetData(
      videoUrl: "https://example.com/video.mp4", // Replace this with the actual video URL.
      coverUrl: "https://example.com/cover.jpg", // Replace this with the actual thumbnail URL.
      videoTitle: "Sample Video",
    );
    _controller.configure(data); // Set autoplay.
  }

  @override
  void dispose() {
    // Destroy the player instance and release resources.
    _controller.destroy();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: AliPlayerWidget(
          _controller,
        ),
      ),
    );
  }
}

Steps

  1. Initialize AliPlayerWidgetController.

    Create the _controller instance in the initState method.

  2. Call the configure API.

    • Use AliPlayerWidgetData to configure the video URL, thumbnail, title, and other information.

    • Call _controller.configure(data) to pass the data to the player component.

  3. Release resources.

    Call _controller.destroy() in the dispose method to prevent memory leaks.

Support for more scenarios

The preceding example shows the basic usage in a VOD scenario. To learn about more complex scenarios, such as live streaming and list playback, see the aliplayer_widget_example sample project. It contains detailed code and instructions.

Sample project

Project description

aliplayer_widget_example is a sample project based on the aliplayer_widget Flutter library. It helps you get started and understand how to integrate and use AliPlayerWidget in your projects.

This sample project shows you how to:

  • Embed the video player component.

  • Configure playback features in different scenarios, such as VOD, live streaming, and list playback.

  • Use custom options to create a personalized user experience.

Compile and run the project

Run from the command line

  1. Clone the repository.

    First, clone the aliplayer_widget_example repository to your local machine:

    cd aliplayer_widget_example
  2. Install dependencies.

    Run the following command to install the required dependencies for the project:

    flutter pub get
  3. Compile the project.

    Compile the Android project

    To compile the Android project, perform the following steps:

    1. Make sure you have installed the Android SDK and Gradle.

    2. Run the following command to generate the APK file:

      flutter build apk
    3. After the compilation is complete, the APK file is located at build/app/outputs/flutter-apk/app-release.apk.

    Compile the iOS project

    To compile the iOS project, perform the following steps:

    1. Make sure you have installed Xcode and CocoaPods.

    2. Initialize the CocoaPods dependencies:

      cd ios && pod install && cd ..
    3. Run the following command to generate the iOS application package (IPA) file:

      flutter build ipa
    4. After the compilation is complete, the IPA file is located at build/ios/ipa/Runner.ipa.

  4. Run the sample.

    • Run the Android sample.

      flutter run lib/main.dart
    • Run the iOS sample.

      cd ios && pod install && cd ..//Run pod install first.
      
      flutter run lib/main.dart

Run from an IDE

  • Use Android Studio

    1. Open the project.

      Start Android Studio. Select Open an Existing Project, and then open the cloned aliplayer_widget_example directory.

    2. Install dependencies.

      In Android Studio, click the pubspec.yaml file, and then click the Pub Get button in the upper-right corner to install the dependencies.

    3. Configure the device.

      Make sure an Android physical device is connected.

    4. Run the application.

      Click the green run button (Run) in the toolbar and select the target device to start the application.

  • Use VS Code

    1. Open the project.

      Start VS Code. Select File -> Open Folder and open the cloned aliplayer_widget_example directory.

    2. Install dependencies.

      Open the terminal (Ctrl + ~) and run the following command to install the dependencies:

      flutter pub get
    3. Configure the device.

      Make sure an Android or iOS physical device is connected. Use the device selector in the bottom-left corner of VS Code to select the target device.

    4. Run the application.

      Press F5 or click the Run and Debug icon in the Activity Bar on the left. Select the Flutter configuration and start the debugging session.

  • Use Xcode (iOS only)

    1. Open the project.

      Navigate to the ios directory and double-click the Runner.xcworkspace file to open the project in Xcode.

    2. Install the CocoaPods dependencies.

      If the CocoaPods dependencies are not installed, run the following command in the terminal:

      cd ios && pod install && cd ..
    3. Configure the signature.

      In Xcode, select the Runner project, go to the Signing & Capabilities tab, and configure a valid developer account and signing certificate.

    4. Run the application.

      Click the run button (▶️) in the Xcode toolbar and select the target device to start the application.

Sample description

The aliplayer_widget_example project covers multiple scenarios. It demonstrates the core features of AliPlayerWidget and its applications. Whether you need a basic VOD playback page, a complex live streaming page, or a short video list playback page, this sample project helps you quickly learn how to integrate and use the component. You can also customize the project as needed.

VOD playback page (LongVideoPage)

Description

This page demonstrates how to use AliPlayerWidget to implement basic VOD playback features.

Result

After the page loads, the specified VOD video automatically plays, and the thumbnail and title are displayed. You can use the control bar to pause, fast-forward, adjust the volume, and perform other operations. The following is a code sample:

@override
void initState() {
  super.initState();
  _controller = AliPlayerWidgetController(context);
  final data = AliPlayerWidgetData(
    videoUrl: "https://example.com/sample-video.mp4",
    coverUrl: "https://example.com/sample-cover.jpg",
    videoTitle: "Sample Video Title",
  );
  _controller.configure(data);
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: AliPlayerWidget(_controller),
  );
}

Live streaming page (LivePage)

Description

This page demonstrates how to configure AliPlayerWidget to support real-time live streaming media playback.

Result

After the page loads, the live stream plays in real time with low latency. You can view messages and send comments in the chat window. The following is a code sample:

@override
void initState() {
  super.initState();
  _controller = AliPlayerWidgetController(context);
  final data = AliPlayerWidgetData(
    videoUrl: "https://example.com/live-stream.m3u8",
    sceneType: SceneType.live,
  );
  _controller.configure(data);
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Column(
      children: [
        Expanded(child: AliPlayerWidget(_controller)),
        _buildChatArea(),
        _buildMessageInput(),
      ],
    ),
  );
}

For information about how to use list playback for short videos, see Integrate the mini-drama solution for Flutter.

Core components

AliPlayerWidget

AliPlayerWidget is the core player component used to embed and play videos in a Flutter application.

Constructor

AliPlayerWidget(
  AliPlayerWidgetController controller, {
  Key? key,
  List<Widget> overlays = const [],
});

Name

Description

controller

The player controller. It is used to manage the playback logic.

overlays

An optional list of overlay components. It is used to overlay a custom UI on the player component.

Example

Expand to view the sample code

AliPlayerWidget(
  _controller,
  overlays: [
    Positioned(
      right: 16,
      bottom: 80,
      child: Column(
        children: [
          IconButton(icon: Icon(Icons.favorite), onPressed: () {}),
          IconButton(icon: Icon(Icons.share), onPressed: () {}),
        ],
      ),
    ),
  ],
);

AliPlayerWidgetController

AliPlayerWidgetController is the core controller of the player component. It is used to manage the initialization, playback, and destruction logic of the player component.

Methods

Name

Description

configure(AliPlayerWidgetData data)

Configures the data source.

play()

Starts playing the video.

pause()

Pauses the playback.

seek(Duration position)

Jumps to a specific playback position.

setUrl(String url)

Sets the video playback URL.

destroy()

Destroys the player instance and releases resources.

Example

// Initialize the player component controller.
final controller = AliPlayerWidgetController(context);

// Set the player component data.
AliPlayerWidgetData data = AliPlayerWidgetData(
  videoUrl: "https://example.com/video.mp4",
);
controller.configure(data);

// Destroy the player.
controller.destroy();

AliPlayerWidgetData

AliPlayerWidgetData is the data model required by the player component. It contains the video URL, thumbnail, title, and other information.

Properties

Name

Description

videoUrl

The video playback URL. This parameter is required.

coverUrl

The thumbnail URL. This parameter is optional.

videoTitle

The video title. This parameter is optional.

thumbnailUrl

The thumbnail URL. This parameter is optional.

sceneType

The playback scenario type. The default value is VOD (SceneType.vod).

Example

AliPlayerWidgetData(
  videoUrl: "https://example.com/video.mp4",
  coverUrl: "https://example.com/cover.jpg",
  videoTitle: "Sample Video",
  sceneType: SceneType.vod,
);

SceneType property

Enumeration value

Description

vod

VOD scenario. Suitable for regular video playback. Supports all playback control features.

live

Live streaming scenario. Suitable for real-time live stream playback. Does not support timeline-related operations such as progress dragging, fast forward or backward, or playback speed adjustment.

listPlayer

List playback scenario. Suitable for players in a video list, such as in a feed or a short video list. Does not support vertical gestures for volume or brightness adjustment.

restricted

Restricted playback scenario. Suitable for scenarios that require limited playback control, such as education, training, or exam monitoring. Does not support timeline-related operations such as progress dragging, fast forward or backward, or playback speed adjustment.

minimal

Minimal playback scenario. Suitable for decorative videos, embedded players, or custom UI overlays. Displays only the video content and hides all UI elements, including the thumbnail, captions, and control interface. Supports fully custom UI requirements.

The following is an example:

_controller = AliPlayerWidgetController(context);
// Set the player component data.
final data = AliPlayerWidgetData(
  sceneType: SceneType.vod
);
_controller.configure(data);

Custom features

Overlay components

You can use the overlays parameter to easily overlay custom UI components, such as Like, Comment, and Share buttons, on the player.

AliPlayerWidget(
  _controller,
  overlays: [
    Positioned(
      right: 16,
      bottom: 80,
      child: Column(
        children: [
          IconButton(icon: Icon(Icons.favorite), onPressed: () {}),
          IconButton(icon: Icon(Icons.comment), onPressed: () {}),
          IconButton(icon: Icon(Icons.share), onPressed: () {}),
        ],
      ),
    ),
  ],
);

Common API calls

AliPlayerWidget provides a series of external API calls that allow you to directly control the player's behavior. These API calls are exposed through AliPlayerWidgetController and support playback control, status queries, data updates, and other features. The following are some common external API calls and their scenarios:

Configuration and initialization

Name

Description

configure

Configures the player data source and initializes the player.

prepare

Prepares the player. This is a manual preparation process.

Playback control

Name

Description

play

Starts playing the video.

pause

Pauses the playback.

stop

Stops the playback and resets the player.

seek

Jumps to a specified playback position.

togglePlayState

Switches the playback state between play and pause.

replay

Replays the video. This is typically used to restart the video after playback is complete.

Playback Property Settings

Name

Description

setSpeed

Sets the playback speed.

setVolume

Sets the volume.

setVolumeWithDelta

Adjusts the volume based on an increment.

setBrightness

Sets the screen brightness.

setBrightnessWithDelta

Adjusts the screen brightness based on an increment.

setLoop

Sets whether to loop the playback.

setMute

Sets whether to mute the audio.

setMirrorMode

Sets the mirror mode, such as horizontal or vertical mirroring.

setRotateMode

Sets the rotation angle, such as 90 or 180 degrees.

setScaleMode

Sets the rendering fill mode, such as stretch or crop.

selectTrack

Switches the playback definition.

Other settings

Name

Description

requestThumbnailBitmap

Requests a thumbnail at a specified time point.

clearCaches

Clears the player cache, including the video cache and image cache.

getWidgetVersion

Gets the version number of the current Flutter widget.

Advanced features

Slot system

Overview
AliPlayerWidget provides a flexible slot system that supports fine-grained customization of the player interface. You can freely combine or replace UI components to create a branded, scenario-specific, or minimalist playback experience.

Slot types
The following core interactive area slots are built-in:

Type

Function

Default display

playerSurface

Player view slot. Renders video content. Customization is not recommended.

Yes

topBar

Top bar slot. Contains the back button, title, and settings button.

Yes

bottomBar

Bottom bar slot. Contains playback controls, progress bar, and full-screen button.

Yes

playControl

Playback control slot. The area for gesture controls.

Yes

coverImage

Thumbnail slot. Displays the thumbnail before the video loads.

Yes (Conditional)

playState

Playback state slot. Displays information such as error messages.

Yes (Conditional)

centerDisplay

Center display slot. Displays volume, brightness, and other indicators during gesture operations.

Yes (Conditional)

seekThumbnail

Seek thumbnail slot. Previews thumbnails when you drag the progress bar.

Yes (Conditional)

subtitle

Caption slot. Displays video captions.

Yes (Conditional)

settingMenu

Settings menu slot. Contains player setting options.

Yes (except in the minimal scenario)

overlays

Overlay slot. Used to add custom overlays.

No

Note
  • Do not modify the playerSurface slot (player view). It is responsible for the core video rendering feature. Modifying it may cause playback exceptions.

  • Conditional means the slot is enabled only in specific states or configurations.

Use the default interface

If you do not configure a slot builder, the full UI is loaded by default. This is suitable for standard playback scenarios.

Widget _buildPlayWidget() {
  return AliPlayerWidget(_controller);
}

Customize specific slots

You can customize specific components as needed and keep the rest as default to reduce maintenance costs.

AliPlayerWidget(
  controller,
  slotBuilders: {
    SlotType.topBar: (context) => MyAppTopBar(title: 'My Video'),
    SlotType.bottomBar: (context) => MyCustomControls(),
  },
)

Customize all slots

AliPlayerWidget(
  controller,
  slotBuilders: {
    SlotType.topBar: (context) => CustomTop(),
    SlotType.bottomBar: (context) => CustomBottom(),
    SlotType.playControl: (context) => GestureHandler(),
    SlotType.coverImage: (context) => BrandCover(),
    SlotType.playState: (context) => ErrorOverlay(),
    SlotType.centerDisplay: (context) => VolumeIndicator(),
    SlotType.seekThumbnail: (context) => PreviewThumb(),
    SlotType.subtitle: (context) => SubtitleView(),
    SlotType.settingMenu: (context) => MySettings(),
    SlotType.overlays: (context) => [AdBanner(), Watermark()],
  },
)

Hide specific slots

Set the slot value to null to hide the corresponding area.

AliPlayerWidget(
  controller,
  slotBuilders: {
    SlotType.topBar: null,        // Hide the top bar.
    SlotType.settingMenu: null,   // Hide the settings menu.
    SlotType.centerDisplay: null, // Disable gesture feedback prompts.
  },
)

The following is a complete example:

// Hide the top and bottom bars for a cleaner interface.
AliPlayerWidget(controller, slotBuilders: {
  SlotType.topBar: null,
  SlotType.bottomBar: null,
});

// Add a custom business overlay.
AliPlayerWidget(controller, slotBuilders: {
  SlotType.overlays: (context) => MyLikeShareButtons(),
});

// Create a fully branded user interface.
AliPlayerWidget(controller, slotBuilders: {
  SlotType.topBar: (context) => MyAppTopBar(),
  SlotType.bottomBar: (context) => MyAppBottomBar(),
  SlotType.settingMenu: null, // Hide settings.
});

Event notifications

AliPlayerWidgetController provides a series of ValueNotifier objects to send real-time notifications about player status changes and user operations. The following are some common notifier objects and their purposes:

Overview of common notifiers

Playback status management

Name

Description

playStateNotifier

Monitors changes in the playback state, such as play, pause, and stop.

playErrorNotifier

Monitors errors that occur during playback and provides error codes and descriptions.

Playback progress management

Name

Description

currentPositionNotifier

Updates the current playback progress in real time. Unit: milliseconds.

bufferedPositionNotifier

Tracks the buffering progress of the video to help you understand the range of cached content.

totalDurationNotifier

Provides information about the total duration of the video. This helps you calculate the playback progress percentage or display the total duration.

Volume and brightness control

Notifier

Description

volumeNotifier

Monitors volume changes and supports dynamic volume adjustment. The value is typically from 0.0 to 1.0.

brightnessNotifier

Monitors screen brightness changes. This lets you adjust the brightness based on the ambient light. The value is typically from 0.0 to 1.0.

Definition and thumbnail

Notifier

Description

currentTrackInfoNotifier

Tracks changes in the current video definition, such as standard definition, high definition, and ultra-high definition. It also provides details about the definition after a switch.

thumbnailNotifier

Monitors the thumbnail loading status to ensure that the corresponding thumbnail preview is displayed in real time when you drag the progress bar.

Video download and screenshot

Notifier

Description

snapFileStateNotifier

Tracks the path status of the current screenshot. When you call snapshot in the controller, this notifier triggers a path change.

downloadStateNotifier

Tracks the video download status. This feature is available only for data of the `vidAuth` or `vidSts` type. Use this to check whether the video is downloaded.

Usage

You can use ValueListenableBuilder to listen for changes from a notifier. This lets you update the UI or execute logic in real time. The following is an example:

// Listen for playback errors.
ValueListenableBuilder<Map<int?, String?>?>(
  valueListenable: _controller.playErrorNotifier,
  builder: (context, error, _) {
    if (error != null) {
      final errorCode = error.keys.firstOrNull;
      final errorMsg = error.values.firstOrNull;
      return Text("Playback error: [$errorCode] $errorMsg");
    }
    return SizedBox.shrink();
  },
);

Features

Multi-scenario adaptation

Supports multiple scenarios, such as VOD, live streaming, list playback, and full-screen playback.

Rich feature set

  • Basic features: Provides core features such as playback control, a settings panel, thumbnail display, and definition switching to meet standard video playback requirements.

  • Gesture control: Supports gesture control for brightness, volume, and playback progress. This provides an intuitive and convenient user experience.

Flexible UI customization

  • Overlay support: Supports custom overlay components for high extensibility. This lets you implement complex features such as advertisements and live comments.

  • Modular design: Provides built-in, reusable UI components, such as a top bar, a bottom bar, and a settings panel, to facilitate custom development.

  • Full-screen adaptation: Automatically adapts to landscape and portrait mode switching to ensure an optimal display effect on different devices.

Event and status management

  • Real-time status monitoring: Provides real-time data updates for playback status, video dimensions, and buffer progress to facilitate dynamic interaction.

  • Event callback mechanism: Provides comprehensive event listeners for the player, including status management for playback start, pause, and completion. This helps you manage various playback scenarios.

  • Logging and debugging support: Provides a detailed logging system to facilitate troubleshooting and performance optimization.

Core advantages

By making simple API calls, you can quickly integrate high-quality video playback features and significantly reduce development costs. AliPlayerWidget handles both basic playback controls and complex interactive scenarios, such as gesture adjustments and overlays. This helps you build a smooth and efficient user experience.

Easy to use

You can implement complex video playback features and quickly integrate them into your Flutter projects by making simple API calls.

Flexible and extensible

  • The modular design supports various custom options to facilitate custom development.

  • Automatically adapts to different screen sizes and resolutions to ensure a consistent user experience.

High performance and stability

  • Built on the ApsaraVideo Player SDK, it provides a low-latency, high-stability video playback experience.

  • The optimized architecture, lightweight components, asynchronous loading, and event-driven model ensure efficient operation and a smooth user experience.

Cross-platform support

Leverages the cross-platform capabilities of Flutter to support both Android and iOS, allowing for single-codebase development for both platforms.

Notes

Resource release

When a page is destroyed, make sure to call the AliPlayerWidgetController.destroy() method to release player resources.

Network permissions

Make sure the application has the necessary network permissions to load online videos.

Thumbnail support

If you want to use the thumbnail feature, make sure a valid thumbnail URL is provided.

Debugging and optimization

We recommend that you enable the logging feature during development to facilitate troubleshooting. In addition, you should optimize the performance of overlay components to avoid affecting playback smoothness.

FAQ

For more information about common issues and solutions when you use the ApsaraVideo Player SDK, see FAQ about ApsaraVideo Player.