init method
Future<int>
init(
- dynamic token, {
- required P2pConfig config,
- void infoListener()?,
- bool bufferedDurationGeneratorEnable = false,
override
Create a new instance with token and the specified config.
Implementation
@override
Future<int> init(
token, {
required P2pConfig config,
void Function(Map<String, dynamic>)? infoListener,
bool bufferedDurationGeneratorEnable = false, // 是否可以给SDK提供缓冲前沿到当前播放时间的差值
}) async {
_bufferedDurationGeneratorEnable = bufferedDurationGeneratorEnable;
final int? success = await _channel.invokeMethod('init', {
'token': token,
'config': config.toMap,
'enableBufferedDurationGenerator': bufferedDurationGeneratorEnable,
});
_channel.setMethodCallHandler((call) async {
if (call.method == 'bufferedDuration') {
var duration = _bufferedDurationGenerator?.call();
return {'result': duration?.inSeconds ?? -1};
}
return {"success": true};
});
if (infoListener != null) {
_eventChannel.receiveBroadcastStream().listen(
(dynamic event) {
var map = Map<String, dynamic>.from(event);
infoListener.call(map);
},
onError: (dynamic error) {
// print('Received error: ${error.message}');
},
cancelOnError: true);
}
if (success == null) {
throw 'Not Avaliable Result: $success. Init fail.';
}
return success;
}