Skip to main content

Getting Started

To use our Flutter player SDK, add tpstreams_player_sdk as a dependency in your pubspec.yaml file.

Initializing TPStreamsSDK​

First, import the package:

import 'package:tpstreams_player_sdk/tpstreams_player_sdk.dart';

Next, initialize the SDK at the entry point of your application (in the main function) before calling runApp:

import 'package:flutter/material.dart';
import 'package:tpstreams_player_sdk/tpstreams_player_sdk.dart';

void main() {
WidgetsFlutterBinding.ensureInitialized();
TPStreamsSDK.initialize(
orgCode: "YOUR_ORG_CODE",
allowFallbackToL3: true, // Optional, defaults to false
);
runApp(const MyApp());
}

Make sure to replace "YOUR_ORG_CODE" with your actual organization code.

Initialization Parameters​

ParameterTypeRequiredDefaultDescription
orgCodeStringYes—Your TPStreams organization code.
providerPROVIDERNoPROVIDER.tpstreamsThe provider type (PROVIDER.tpstreams).
authTokenString?NonullOptional authentication token for protected resources.
allowFallbackToL3boolNofalseEnables automatic fallback to software decryption (Widevine L3) if hardware DRM (L1) fails on Android devices.
Widevine L3 Fallback (allowFallbackToL3)

allowFallbackToL3 is an optional boolean parameter in TPStreamsSDK.initialize (default: false).

On Android devices, Widevine DRM operates at two primary security levels:

  • Widevine L1 (Hardware-level): Decryption and rendering occur entirely in the device's hardware Trusted Execution Environment (TEE).
  • Widevine L3 (Software-level): Decryption occurs via software.

Why enable L3 fallback?

  • Hardware & OEM DRM issues: On certain Android devices (e.g., devices with custom ROMs, corrupted keystores, or buggy OEM DRM implementations), hardware L1 decryption may fail and cause DRM playback to break completely.
  • MediaTek & low-end device decoder limits (Error 4003): Error 4003 is commonly observed on low-end MediaTek devices where releasing the secure hardware decoder of an earlier player instance takes time. Due to the limited number of hardware secure decoders on these chipsets, the player fails to create a secure decoder instance.

Setting allowFallbackToL3: true instructs the native Android player to automatically fall back to software decryption (L3) in such error scenarios to avoid demanding a hardware secure decoder, preventing playback failures.

Android Setup​

In the Android directory, extend the FlutterFragmentActivity class in your MainActivity file.

To do this, make the change in the following directory: android/app/src/main/kotlin/com/project_name/MainActivity.kt

import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterFragmentActivity(){

}

Play a Video​

To play a video using the TPStreams Player SDK, use the TPStreamPlayer widget:

TPStreamPlayer(assetId: 'ASSET_ID', accessToken: 'ACCESS_TOKEN')

Replace ASSET_ID and ACCESS_TOKEN with the actual assetId and accessToken of the video you wish to play. After executing your Flutter application, the TPStreams player will display the video specified by the provided assetId and accessToken.

TPStreamPlayer Configuration​

The TPStreamPlayer widget accepts the following parameters:

ParameterTypeDefaultDescription
assetIdString—Unique identifier of the video asset (required).
accessTokenString?nullAccess token for the video.
aspectRatiodouble16 / 9Aspect ratio of the player view.
onPlayerCreatedFunction(TPStreamsPlayerController)?nullCallback invoked when the player is created. Provides the controller for controlling playback.
showDownloadOptionbool?falseShows the download button in the player UI.
startInFullscreenbool?falseLaunches the player directly in fullscreen mode.
offlineLicenseExpireDaysint?15Duration in days for which the offline license is valid.
metadataMap<String, String>?nullCustom key-value pairs to attach to the player.
autoPlaybooltrueWhether playback starts automatically once the video is loaded.
resolutionint?nullInitial playback quality as the maximum video height in pixels (e.g., 720 for 720p).
userIdString?nullIdentifier of the signed-in viewer. When provided, playback resumes from the last watched position.
preferencesTPStreamsPlayerPreferences?defaultsConfigures which player UI elements are shown (see below).

TPStreamsPlayerPreferences​

Use TPStreamsPlayerPreferences to control which UI elements are available in the player.

TPStreamPlayer(
assetId: 'ASSET_ID',
accessToken: 'ACCESS_TOKEN',
preferences: TPStreamsPlayerPreferences(
enableFullscreen: true, // Show the fullscreen button
enablePlaybackSpeed: true, // Show playback speed options
enableCaptions: true, // Show captions/CC options
showResolutionOptions: true, // Show video quality options
enableSeekButtons: true, // Show forward/backward seek buttons
seekBarColor: Colors.blue.value, // Optional: tint the seek bar
),
)
ParameterTypeDefaultDescription
enableFullscreenbooltrueEnables the fullscreen button.
enablePlaybackSpeedbooltrueEnables playback speed controls.
enableCaptionsbooltrueEnables caption/subtitle controls.
showResolutionOptionsbooltrueEnables video quality selection.
enableSeekButtonsbooltrueEnables forward/backward seek buttons.
seekBarColorint?null(Optional) Color of the seek bar as an ARGB integer (e.g., Colors.blue.value).

Control Video Playback​

To control the video playback (e.g., play, pause, seek), you need to get a reference to the TPStreamsPlayerController. This controller is passed via the onPlayerCreated callback when the player widget is initialized.

TPStreamPlayer(
assetId: 'ASSET_ID',
accessToken: 'ACCESS_TOKEN',
onPlayerCreated: _onPlayerCreated,
)

void _onPlayerCreated(TPStreamsPlayerController controller) {
// Store the controller for later use
this.controller = controller;
}

For a practical implementation and usage of tpstreams_player_sdk, refer to our Sample Flutter App.