Skip to content

Commit ef0b0d4

Browse files
authored
Add availability checks and detailed error handling for video adapters
1 parent cf92820 commit ef0b0d4

File tree

4 files changed

+74
-6
lines changed

4 files changed

+74
-6
lines changed

src/adapters/ExpoAVVideoAdapter.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,36 @@ export class ExpoAVVideoAdapter implements VideoPlayerAdapter {
2020
return !!(this.expoAVModule && this.expoAVModule.Video);
2121
}
2222

23+
getAvailabilityInfo(): { isAvailable: boolean; error?: string; installCommand?: string; packageName?: string } {
24+
if (!this.expoAVModule) {
25+
return {
26+
isAvailable: false,
27+
error: "ExpoAVVideoAdapter: Module not found. Please install expo-av to enable video playback functionality.",
28+
installCommand: "npx expo install expo-av",
29+
packageName: "expo-av"
30+
};
31+
}
32+
33+
if (!this.expoAVModule.Video) {
34+
return {
35+
isAvailable: false,
36+
error: "ExpoAVVideoAdapter: Video component not found in expo-av. Please ensure you have a compatible version installed.",
37+
installCommand: "npx expo install expo-av",
38+
packageName: "expo-av"
39+
};
40+
}
41+
42+
return { isAvailable: true };
43+
}
44+
2345
getAdapterName(): string {
2446
return VideoPlayerType.EXPO_AV;
2547
}
2648

2749
renderVideo(props: VideoPlayerProps, ref: RefObject<VideoPlayerRef | null>): ReactElement {
28-
if (!this.isAvailable()) {
29-
throw new Error('expo-av is not available');
50+
const availabilityInfo = this.getAvailabilityInfo();
51+
if (!availabilityInfo.isAvailable) {
52+
throw new Error(`${availabilityInfo.error}\n\nTo fix this issue, run: ${availabilityInfo.installCommand}`);
3053
}
3154

3255
const { Video } = this.expoAVModule;

src/adapters/ExpoVideoAdapter.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,45 @@ export class ExpoVideoAdapter implements VideoPlayerAdapter {
2525
return !!(this.expoVideoModule && this.expoVideoModule.VideoView);
2626
}
2727

28+
getAvailabilityInfo(): { isAvailable: boolean; error?: string; installCommand?: string; packageName?: string } {
29+
if (!this.expoVideoModule) {
30+
return {
31+
isAvailable: false,
32+
error: "ExpoVideoAdapter: Module not found. Please install expo-video to enable video playback functionality.",
33+
installCommand: "npx expo install expo-video",
34+
packageName: "expo-video"
35+
};
36+
}
37+
38+
if (!this.expoVideoModule.VideoView) {
39+
return {
40+
isAvailable: false,
41+
error: "ExpoVideoAdapter: VideoView component not found in expo-video. Please ensure you have a compatible version installed.",
42+
installCommand: "npx expo install expo-video",
43+
packageName: "expo-video"
44+
};
45+
}
46+
47+
if (!this.expoVideoModule.createVideoPlayer) {
48+
return {
49+
isAvailable: false,
50+
error: "ExpoVideoAdapter: createVideoPlayer function not found in expo-video. Please ensure you have a compatible version installed.",
51+
installCommand: "npx expo install expo-video",
52+
packageName: "expo-video"
53+
};
54+
}
55+
56+
return { isAvailable: true };
57+
}
58+
2859
getAdapterName(): string {
2960
return VideoPlayerType.EXPO_VIDEO;
3061
}
3162

3263
renderVideo(props: VideoPlayerProps, ref: RefObject<VideoPlayerRef | null>): ReactElement {
33-
34-
if (!this.isAvailable()) {
35-
throw new Error('expo-video is not available');
64+
const availabilityInfo = this.getAvailabilityInfo();
65+
if (!availabilityInfo.isAvailable) {
66+
throw new Error(`${availabilityInfo.error}\n\nTo fix this issue, run: ${availabilityInfo.installCommand}`);
3667
}
3768

3869
const { VideoView, createVideoPlayer } = this.expoVideoModule;

src/adapters/FallbackVideoAdapter.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ export class FallbackVideoAdapter implements VideoPlayerAdapter {
1010
}
1111

1212
isAvailable(): boolean {
13-
return true; // Fallback is always available
13+
return true;
14+
}
15+
16+
getAvailabilityInfo(): { isAvailable: boolean; error?: string; installCommand?: string; packageName?: string } {
17+
return { isAvailable: true };
1418
}
1519

1620
getAdapterName(): string {

src/adapters/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ export interface VideoPlayerAdapter {
2626
*/
2727
isAvailable(): boolean;
2828

29+
/**
30+
* Get detailed availability information including error context and installation guidance
31+
*/
32+
getAvailabilityInfo(): {
33+
isAvailable: boolean;
34+
error?: string;
35+
installCommand?: string;
36+
packageName?: string;
37+
};
38+
2939
/**
3040
* Get the display name of this adapter
3141
*/

0 commit comments

Comments
 (0)