Usage
# Installation
Add this to your package's pubspec.yaml file:
dependencies:
cdnbye: ^0.8.1
# iOS
Uncomment # platform :ios, '10.0' at the second line of ios/Podfile in your flutter project.
In order to allow the loading of distributed content via the local proxy, enable loading data from HTTP in your app by opening your info.plist file as source code and adding the following values below the tag:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
# Android
Please set minSdkVersion to 19.
Add relevant uses permissions in app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<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_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Starting with Android 9 (API level 28), cleartext support is disabled by default. There are 2 solutions:
(1) set targetSdkVersion under 27
(2) Add the attribute below in app/src/main/AndroidManifest.xml to indicate that the app intends to use cleartext HTTP:
<application
...
android:usesCleartextTraffic="true"
...
/>
# Example
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:cdnbye/cdnbye.dart';
// Init p2p engine
_initEngine();
// Start playing video
_loadVideo();
_initEngine() async {
await Cdnbye.init(
YOUR_TOKEN,
config: P2pConfig.byDefault()
);
}
_loadVideo() async {
var url = YOUR_STREAM_URL;
url = await Cdnbye.parseStreamURL(url); // Parse your stream url
player = VideoPlayerController.network(url);
}