Skip to main content

Usage

Installation

Add this to your package's pubspec.yaml file:

  flutter pub add flutter_p2p_engine

iOS

  • Add platform :ios, '13.0' in ios/Podfile .
  • Open ios/Runner.xcworkspace by xcode, change Minimum Developments Target to 13.0.

macOS

  • Edit macos/Runner/Release.entitlements & macos/Runner/DebugProfile.entitlements:
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.app-sandbox</key>
<false/>
  • Add platform :osx, '10.15' in macos/Podfile .
  • Open macos/Runner.xcworkspace by xcode, change Minimum Developments Target to 10.15.

Android

  • Edit android/app/src/main/AndroidManifest.xml to add the following permissions inside manifest tag:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
...
android:usesCleartextTraffic="true"
...
/>
tip

The below instructions are for the release builds, debug builds should work without any additional steps.

  • Create / append to the file android/app/proguard-rules.pro
-dontwarn com.p2pengine.**
-keep class com.p2pengine.**{*;}
-keep interface com.p2pengine.**{*;}
-keep class com.cdnbye.libdc.**{*;}
-keep interface com.cdnbye.libdc.**{*;}
-keep class com.snapchat.djinni.**{*;}
  • In your android/app/build.gradle edit the release configuration and add the following line importing the proguard configuration
buildTypes {
release {
...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Example

import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:flutter_p2p_engine/flutter_p2p_engine.dart';

// Init p2p engine
_initEngine();

// Start playing video
_loadVideo();

_initEngine() async {
await FlutterP2pEngine.init(
YOUR_TOKEN,
config: P2pConfig(
trackerZone: TrackerZone.Europe, // Set HongKong or USA if you changed zone
),
);
}

_loadVideo() async {
var url = YOUR_STREAM_URL;
url = await FlutterP2pEngine.parseStreamURL(url); // Parse your stream url
player = VideoPlayerController.networkUrl(url);
}

Where YOUR_TOKEN is your Customer ID. Please replace it by your own token obtained from console, click here for more information.