The ApsaraVideo Player SDK for Flutter provides an efficient solution for integrating audio and video features into mobile applications. It allows developers to quickly implement core video scenarios, such as live streaming and video-on-demand. This topic describes the live streaming playback feature of the ApsaraVideo Player SDK for Flutter.
Standard live streaming playback
Integrate the SDK.
For more information, see Integrate the ApsaraVideo Player SDK for Flutter.
Implement live streaming playback.
Get started.
To implement basic playback, see Quick start for ApsaraVideo Player for Flutter.
Set the live stream source.
The ApsaraVideo Player SDK for Flutter supports only the UrlSource method for live stream playback.
Play a live stream using UrlSource
To play a live stream using the UrlSource method, set the setUrl property of the player to the streaming URL. The URL can be from a third-party provider or a stream pulling URL from ApsaraVideo Live.
You can use the URL generator in the ApsaraVideo Live console to generate a stream pulling URL. For more information, see ApsaraVideo Live URL generator.
void onViewPlayerCreated(viewId) async { // Set the rendering view for the player. fAliplayer.setPlayerView(viewId); // Set the playback source. switch (_playMode) { // UrlSource playback method. case ModeType.URL: this.fAliplayer.setUrl("Enter the playback URL of the resource."); // The playback URL can be a third-party streaming URL or a stream pulling URL from ApsaraVideo Live. break; default: } }
RTS live streaming playback
The version numbers mentioned in this section are for reference only. Use the version numbers that are required for your integration.
The ApsaraVideo Player SDK and the Real-Time Streaming (RTS) SDK versions must be compatible. For more information about version compatibility, see Web SDK downloads and release notes.
For the specific version numbers of the ApsaraVideo Player SDK, see Android SDK release history and iOS SDK release history. For the version number of the RTS SDK, see Web SDK downloads and release notes.
Integrate the native SDK for Android or iOS.
For Android integration, add the dependencies to the build.gradle file, as shown in the following example.
dependencies{ def player_sdk_version = "7.2.0" def rts_sdk_version = "7.2.0" // The bridge layer between the player and RTS (AlivcArtc). The version number must match the player's version number. This must be integrated with the RTS component. implementation 'com.aliyun.sdk.android:AlivcArtc:$player_sdk_version' // The RTS component. It has an independent version number. implementation 'com.aliyun.rts.android:RtsSDK:$rts_sdk_version' }For iOS integration, add the dependencies to the Podfile file, as shown in the following example.
# player_sdk_version is the version number of the ApsaraVideo Player SDK for iOS, for example, 7.2.0. player_sdk_version = '7.2.0' # rts_sdk_version is the version number of the RTS SDK, which is independent, for example, 7.2.0. rts_sdk_version = '7.2.0' target 'Runner' do flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) # The bridge layer between the player and RTS (AlivcArtc). The version number must match the player's version number. This must be integrated with the RTS component. pod 'AliPlayerSDK_iOS_ARTC', player_sdk_version # The RTS component. pod 'RtsSDK', rts_sdk_version end
To play an Alibaba Real-Time Communication (ARTC) stream, you must import the RTS-related dependencies during integration. For Android, you must also call FlutterAliPlayerFactory.loadRtsLibrary(); to load the RTS SDK dynamic library before you create the player. The following example shows this process:
Configure the
pubspec.yamlfile.name: your_project description: A new Flutter project. version: 1.0.0+1 # The following line prevents the package from being accidentally published to # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you want to publish to pub.dev environment: sdk: ">=2.15.0 <4.0.0" dependencies: flutter: sdk: flutter // Add flutter_aliplayer. flutter_aliplayer: "7.3.1" dev_dependencies: flutter_test: sdk: flutter # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec # The following section is specific to Flutter. flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: trueLoad the RTS SDK.
NoteIf you use ApsaraVideo Player for Android V7.3.1 or earlier, you must manually load the RTS SDK.
If
useAIOFramework=true, the All-in-One Media SDK is used. Otherwise, the ApsaraVideo Player SDK and the RTS SDK are used. The default value of this property is false.Use the latest SDK versions:
For the All-in-One Media SDK, see All-in-One Media SDK for Android and All-in-One Media SDK for iOS.
For the ApsaraVideo Player SDK, see Download ApsaraVideo Player SDK.
For the RTS component, see Implement RTS stream pulling on Android and Implement RTS stream pulling on iOS.
dependencies { // Define the SDK kernel. def useAIOFramework = false // Define the SDK versions. // All-in-One Media SDK. def aio_sdk_version = "7.1.0" // ApsaraVideo Player SDK. def player_sdk_version = "7.2.0" // RTS component. def rts_sdk_version = "7.2.0" // Select the SDK based on the value of useAIOFramework. if (useAIOFramework) { // All-in-One Media SDK (interactive stream): stream ingest (including RTS and RTC co-streaming) + player. implementation "com.aliyun.aio:AliVCSDK_InteractiveLive:$aio_sdk_version" } else { // Standalone ApsaraVideo Player SDK. implementation "com.aliyun.sdk.android:AliyunPlayer:$player_sdk_version-full" implementation "com.aliyun.sdk.android:AlivcArtc:$player_sdk_version" implementation "com.aliyun.rts.android:RtsSDK:$rts_sdk_version" } implementation 'com.google.code.gson:gson:2.10.1' }Manually load the RTS SDK.
FlutterAliPlayerFactory.loadRtsLibrary(true);Play the video.
FlutterAliplayer player = FlutterAliPlayerFactory.createAliPlayer(); player.setUrl("artc://xxxx"); player.prepare(); player.play();