Usage
Installation
Add this to your package's pubspec.yaml file:
flutter pub add flutter_p2p_engine
iOS
- Add platform :ios, '13.0' to ios/Podfile .
- Open ios/Runner.xcworkspace in Xcode and change the Minimum Deployment 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' to macos/Podfile .
- Open macos/Runner.xcworkspace in Xcode and change the Minimum Deployment Target to 10.15.
Android
- Edit android/app/src/main/AndroidManifest.xml to add the following permissions inside the 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 instructions below apply to release builds; debug builds should work without any additional steps.
- Create or 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 to import 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);
}
YOUR_TOKEN represents your Customer ID. Replace it with the token obtained from your console; click here for more information.