create method
Creates an instance of a video player and returns its textureId.
Implementation
@override
Future<int?> create(DataSource dataSource) async {
if (dataSource.sourceType == DataSourceType.file) {
// dataSource.uri is url encoded and has a file:// scheme.
// But if the dataSource.uri original path contains non-ASCII characters,
// it will cause the IMFSourceResolver API url decoding to fail and cause
// the app to crash.
//
// To avoid this, need to pass dataSource.uri to Uri.parse() and get
// the path from uri.toFilePath(). It removes the file:// scheme and
// url decodes the path.
//
// Without the file:// scheme, the IMFSourceResolver API treats the "%"
// character as a normal string instead of url decoding the path.
var uri = Uri.parse(dataSource.uri!);
var controller = WinVideoPlayerController.file(File(uri.toFilePath()),
isBridgeMode: true);
await controller.initialize();
if (controller.textureId_ > 0) {
mControllerMap[controller.textureId_] = controller;
return controller.textureId_;
}
return null;
} else if (dataSource.sourceType == DataSourceType.network) {
var controller =
WinVideoPlayerController.network(dataSource.uri!, isBridgeMode: true);
await controller.initialize();
if (controller.textureId_ > 0) {
mControllerMap[controller.textureId_] = controller;
return controller.textureId_;
}
} else {
throw UnimplementedError(
'create() has not been implemented for dataSource type [assets] and [contentUri] in Windows OS');
}
}