videoEventsFor method
Returns a Stream of VideoEventTypes.
Implementation
@override
Stream<VideoEvent> videoEventsFor(int? textureId) {
return _eventChannelFor(textureId)
.receiveBroadcastStream()
.map((dynamic event) {
late Map<dynamic, dynamic> map;
if (event is Map) {
map = event;
}
final String? eventType = map["event"] as String?;
final String? key = map["key"] as String?;
switch (eventType) {
case 'initialized':
double width = 0;
double height = 0;
try {
if (map.containsKey("width")) {
final num widthNum = map["width"] as num;
width = widthNum.toDouble();
}
if (map.containsKey("height")) {
final num heightNum = map["height"] as num;
height = heightNum.toDouble();
}
} catch (exception) {
PipFlutterPlayerUtils.log(exception.toString());
}
final Size size = Size(width, height);
return VideoEvent(
eventType: VideoEventType.initialized,
key: key,
duration: Duration(milliseconds: map['duration'] as int),
size: size,
);
case 'completed':
return VideoEvent(
eventType: VideoEventType.completed,
key: key,
);
case 'bufferingUpdate':
final List<dynamic> values = map['values'] as List;
return VideoEvent(
eventType: VideoEventType.bufferingUpdate,
key: key,
buffered: values.map<DurationRange>(_toDurationRange).toList(),
);
case 'bufferingStart':
return VideoEvent(
eventType: VideoEventType.bufferingStart,
key: key,
);
case 'bufferingEnd':
return VideoEvent(
eventType: VideoEventType.bufferingEnd,
key: key,
);
case 'play':
return VideoEvent(
eventType: VideoEventType.play,
key: key,
);
case 'pause':
return VideoEvent(
eventType: VideoEventType.pause,
key: key,
);
case 'seek':
return VideoEvent(
eventType: VideoEventType.seek,
key: key,
position: Duration(milliseconds: map['position'] as int),
);
case 'pipStart':
return VideoEvent(
eventType: VideoEventType.pipStart,
key: key,
);
case 'pipStop':
return VideoEvent(
eventType: VideoEventType.pipStop,
key: key,
);
default:
return VideoEvent(
eventType: VideoEventType.unknown,
key: key,
);
}
});
}