[video_player] added iOS exception on incorrect asset path (#4318)

surfaced the incorrect asset path error to dart using try catch.

Fixes [#118660](https://github.com/flutter/flutter/issues/118660)
This commit is contained in:
Zaldy Pagaduan Jr
2023-07-14 11:04:58 +08:00
committed by GitHub
parent 77bb4d930d
commit 4c1149744d
4 changed files with 24 additions and 6 deletions

View File

@ -1,6 +1,7 @@
## NEXT
## 2.4.7
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.
* Adds iOS exception on incorrect asset path
## 2.4.6

View File

@ -620,10 +620,15 @@ NS_INLINE UIViewController *rootViewController(void) {
} else {
assetPath = [_registrar lookupKeyForAsset:input.asset];
}
player = [[FLTVideoPlayer alloc] initWithAsset:assetPath
frameUpdater:frameUpdater
playerFactory:_playerFactory];
return [self onPlayerSetup:player frameUpdater:frameUpdater];
@try {
player = [[FLTVideoPlayer alloc] initWithAsset:assetPath
frameUpdater:frameUpdater
playerFactory:_playerFactory];
return [self onPlayerSetup:player frameUpdater:frameUpdater];
} @catch (NSException *exception) {
*error = [FlutterError errorWithCode:@"video_player" message:exception.reason details:nil];
return nil;
}
} else if (input.uri) {
player = [[FLTVideoPlayer alloc] initWithURL:[NSURL URLWithString:input.uri]
frameUpdater:frameUpdater

View File

@ -2,7 +2,7 @@ name: video_player_avfoundation
description: iOS implementation of the video_player plugin.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.4.6
version: 2.4.7
environment:
sdk: ">=2.18.0 <4.0.0"

View File

@ -135,6 +135,18 @@ void main() {
expect(textureId, 3);
});
test('create with incorrect asset throws exception', () async {
try {
await player.create(DataSource(
sourceType: DataSourceType.asset,
asset: '/path/to/incorrect_asset',
));
fail('should throw PlatformException');
} catch (e) {
expect(e, isException);
}
});
test('create with network', () async {
final int? textureId = await player.create(DataSource(
sourceType: DataSourceType.network,