fix: iOS only supports vtt captions

This commit is contained in:
Adrian Castro
2024-02-11 22:31:42 +01:00
parent 07096f0dec
commit 7483d6b973
2 changed files with 14 additions and 8 deletions

View File

@@ -46,7 +46,7 @@ const defineConfig = (): ExpoConfig => ({
[ [
"expo-screen-orientation", "expo-screen-orientation",
{ {
initialOrientation: "DEFAULT", initialOrientation: "PORTRAIT_UP",
}, },
], ],
[ [

View File

@@ -4,7 +4,7 @@ import type {
TextTracks, TextTracks,
} from "react-native-video"; } from "react-native-video";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { ActivityIndicator, View } from "react-native"; import { ActivityIndicator, Platform, View } from "react-native";
import Video, { TextTracksType } from "react-native-video"; import Video, { TextTracksType } from "react-native-video";
import { useLocalSearchParams, useRouter } from "expo-router"; import { useLocalSearchParams, useRouter } from "expo-router";
import * as ScreenOrientation from "expo-screen-orientation"; import * as ScreenOrientation from "expo-screen-orientation";
@@ -173,10 +173,16 @@ const captionTypeToTextTracksType = {
}; };
function convertCaptionsToTextTracks(captions: Caption[]): TextTracks { function convertCaptionsToTextTracks(captions: Caption[]): TextTracks {
return captions.map((caption) => ({ return captions.map((caption) => {
title: caption.language, if (Platform.OS === "ios" && caption.type !== "vtt") {
language: caption.language as ISO639_1, return null;
type: captionTypeToTextTracksType[caption.type] || TextTracksType.VTT, }
uri: caption.url,
})); return {
title: caption.language,
language: caption.language as ISO639_1,
type: captionTypeToTextTracksType[caption.type],
uri: caption.url,
};
}).filter(Boolean) as TextTracks;
} }