Skip to content

Commit 4c11497

Browse files
authored
[video_player] added iOS exception on incorrect asset path (#4318)
surfaced the incorrect asset path error to dart using try catch. Fixes [#118660](flutter/flutter#118660)
1 parent 77bb4d9 commit 4c11497

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

packages/video_player/video_player_avfoundation/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 2.4.7
22

33
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.
4+
* Adds iOS exception on incorrect asset path
45

56
## 2.4.6
67

packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,15 @@ - (FLTTextureMessage *)create:(FLTCreateMessage *)input error:(FlutterError **)e
620620
} else {
621621
assetPath = [_registrar lookupKeyForAsset:input.asset];
622622
}
623-
player = [[FLTVideoPlayer alloc] initWithAsset:assetPath
624-
frameUpdater:frameUpdater
625-
playerFactory:_playerFactory];
626-
return [self onPlayerSetup:player frameUpdater:frameUpdater];
623+
@try {
624+
player = [[FLTVideoPlayer alloc] initWithAsset:assetPath
625+
frameUpdater:frameUpdater
626+
playerFactory:_playerFactory];
627+
return [self onPlayerSetup:player frameUpdater:frameUpdater];
628+
} @catch (NSException *exception) {
629+
*error = [FlutterError errorWithCode:@"video_player" message:exception.reason details:nil];
630+
return nil;
631+
}
627632
} else if (input.uri) {
628633
player = [[FLTVideoPlayer alloc] initWithURL:[NSURL URLWithString:input.uri]
629634
frameUpdater:frameUpdater

packages/video_player/video_player_avfoundation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_avfoundation
22
description: iOS implementation of the video_player plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.4.6
5+
version: 2.4.7
66

77
environment:
88
sdk: ">=2.18.0 <4.0.0"

packages/video_player/video_player_avfoundation/test/avfoundation_video_player_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ void main() {
135135
expect(textureId, 3);
136136
});
137137

138+
test('create with incorrect asset throws exception', () async {
139+
try {
140+
await player.create(DataSource(
141+
sourceType: DataSourceType.asset,
142+
asset: '/path/to/incorrect_asset',
143+
));
144+
fail('should throw PlatformException');
145+
} catch (e) {
146+
expect(e, isException);
147+
}
148+
});
149+
138150
test('create with network', () async {
139151
final int? textureId = await player.create(DataSource(
140152
sourceType: DataSourceType.network,

0 commit comments

Comments
 (0)