Files
discord-decomp/modules/quests/native/VideoQuestModal/VideoQuestPlayer.tsx
T
2026-11-01 12:12:55 +02:00

892 lines
32 KiB
TypeScript

// Metro module 14160 (f14161).
import * as Module19 from "react";
import { useRef, useMemo, useState, useCallback, useEffect, useLayoutEffect } from "react";
import { ActivityIndicator, Pressable, View, StyleSheet } from "react-native";
import AppStateStore from "../../../../stores/native/AppStateStore";
import VideoQuestUIStore from "../../VideoQuestUIStore";
import { QuestsExperimentLocations } from "../../QuestConstants";
import { AppStates, ComponentActions } from "../../../../Constants";
import Module712 from "../../../../_bundle/Module712";
import Video from "../../../../_bundle/Video_8143";
import { createStyles } from "../../../../design/components/Styles/native/createStyles";
import Module689 from "../../../../_bundle/Module689";
import { useVideoQuestModalContext } from "./VideoQuestModalContext";
import { useQuestTaskDetails } from "../../hooks/QuestHooks";
import { getQuestAsset, QuestAssetType } from "../../lib/AssetUtils";
import { shallow } from "../../../../_bundle/Module3802";
import ReanimatedRexport, { useSharedValue, useAnimatedStyle } from "../../../reanimated/ReanimatedRexport";
import * as _spring from "../../../../design/animation/reanimated/spring/spring";
import * as _springPresets from "../../../../design/animation/reanimated/spring/springPresets";
import * as _timing from "../../../../design/animation/reanimated/timing/timing";
import * as _timingPresets from "../../../../design/animation/reanimated/timing/timingPresets";
import useVideoQuestPlayerAnalytics from "./hooks/useVideoQuestPlayerAnalytics";
import { getDefaultWatchVideoTask } from "../../utils/QuestTaskUtils";
import { getVideoQoEMetricsConfig, MobileMuxWrapper } from "../../../video-qoe/index";
import { getConstants } from "../../../../utils/native/ClientInfoUtils";
import { isAndroid, isIOS } from "../../../../utils/PlatformUtils";
import { ComponentDispatch } from "../../../../utils/ComponentDispatchUtils";
import { sendVideoProgress } from "../../utils/VideoQuestUtils";
import { updateOptimisticProgress } from "../../QuestActionCreators";
import { useStateFromStores } from "../../../../_bundle/Module589";
import SentryUtils_native from "../../../../utils/SentryUtils.native";
import useSafeAreaInsets_native from "../../../safe_area/useSafeAreaInsets.native";
import { intl, t } from "../../../../intl/index.native";
import { VideoQuestCaptions } from "./captions/VideoQuestCaptions";
import { PressableOpacity } from "../../../../design/void/Pressables/native/Pressables";
import { ClosedCaptionsOutlineIcon } from "../../../../design/components/Icon/native/redesign/generated/ClosedCaptionsOutlineIcon";
import { TranscriptOutlineIcon } from "../../../../design/components/Icon/native/redesign/generated/TranscriptOutlineIcon";
import { VideoQuestPlayerControlButton } from "./VideoQuestPlayerControlButton";
import { SkipBackwardIcon } from "./icons/SkipBackwardIcon";
import { RetryIcon } from "../../../../design/components/Icon/native/redesign/generated/RetryIcon";
import { PlayIcon } from "../../../../design/components/Icon/native/redesign/generated/PlayIcon";
import { PauseIcon } from "../../../../design/components/Icon/native/redesign/generated/PauseIcon";
import { SkipForwardIcon } from "./icons/SkipForwardIcon";
import { FullscreenEnterIcon } from "../../../../design/components/Icon/native/redesign/generated/FullscreenEnterIcon";
let hasVideoEnded, canSeekForward, useStyles, PlayerState, __initData, __initData2, __initData3;
let c9911_15 = {
left: Module712.space.PX_16,
right: Module712.space.PX_16,
top: Module712.space.PX_16,
bottom: Module712.space.PX_16
};
let Component = Module19.memo(Video);
const hasVideoEnded2 = function hasVideoEnded(a0, a1) {
return a0 >= a1 - 1;
};
hasVideoEnded2.__closure = {};
hasVideoEnded2.__workletHash = 3281537893520;
hasVideoEnded2.__initData = {
code: "function hasVideoEnded_VideoQuestPlayerTsx1(currentTime,videoDuration){return currentTime>=videoDuration-1;}"
};
hasVideoEnded = hasVideoEnded2;
const canSeekForward2 = function canSeekForward(a0, a1, a2, a3) {
const r2 = a0 >= a2 - 1;
return r2 ? !r2 : a3 ? a3 : a0 <= a1 - 1;
};
canSeekForward2.__closure = {
hasVideoEnded
};
canSeekForward2.__workletHash = 741911733910;
canSeekForward2.__initData = {
code: "function canSeekForward_VideoQuestPlayerTsx2(currentTime,maxTimestamp,videoDuration,isQuestCompleted){const{hasVideoEnded}=this.__closure;return!hasVideoEnded(currentTime,videoDuration)&&(isQuestCompleted||currentTime<=maxTimestamp-1);}"
};
canSeekForward = canSeekForward2;
useStyles = createStyles({
container: {
...StyleSheet.absoluteFillObject
},
loadingContainer: {
...StyleSheet.absoluteFillObject,
backgroundColor: Module712.colors.BACKGROUND_BASE_LOWEST,
justifyContent: "center",
alignItems: "center"
},
bufferingSpinner: {
position: "absolute"
},
bufferingSpinnerCentered: {
...StyleSheet.absoluteFillObject,
justifyContent: "center",
alignItems: "center"
},
video: {
height: "100%",
width: "100%"
},
videoContainer: {
position: "relative",
height: "100%",
width: "100%"
},
controls: {
...StyleSheet.absoluteFillObject,
backgroundColor: Module689(Module712.unsafe_rawColors.BLACK).alpha(0.5).hex(),
justifyContent: "center",
alignItems: "center",
flexDirection: "column"
},
controlsTopBottom: {
flexDirection: "row",
justifyContent: "flex-end",
padding: Module712.space.PX_8,
position: "absolute",
left: 0,
right: 0
},
controlsMiddle: {
justifyContent: "center",
alignItems: "center",
flexGrow: 1,
flexDirection: "row",
gap: Module712.space.PX_24,
pointerEvents: "box-none"
},
controlsTop: {
top: 0
},
controlsBottom: {
bottom: 0
},
progressContainer: {
position: "absolute",
bottom: 0,
right: 0,
left: 0,
justifyContent: "flex-end",
height: Module712.space.PX_16,
overflow: "hidden"
},
progress: {
height: 1,
backgroundColor: Module712.colors.WHITE,
shadowOffset: {
width: 0,
height: 0
},
shadowRadius: 6,
shadowOpacity: 1,
elevation: 5,
shadowColor: "#FFFFFF"
},
icon: {
color: Module712.colors.TEXT_DEFAULT
},
iconDisabled: {
color: Module712.colors.TEXT_SUBTLE
},
controlButton: {
padding: Module712.space.PX_8
}
});
PlayerState = {
PAUSED: "paused",
PLAYING: "playing",
ENDED: "ended",
LOADING: "loading",
ERRORED: "errored"
};
__initData = {
code: "function shouldShowControls_VideoQuestPlayerTsx3(){const{hasLoaded,showControls,playerState,PlayerState,isVideoEnded,externallyPaused}=this.__closure;return hasLoaded&&(showControls.get()||playerState===PlayerState.PAUSED||playerState===PlayerState.ENDED||playerState===PlayerState.ERRORED||isVideoEnded||externallyPaused);}"
};
__initData2 = {
code: "function VideoQuestPlayerTsx4(){const{shouldShowControls,withSpring,SUBTLE_SPRING}=this.__closure;const show=shouldShowControls();return{opacity:withSpring(show?1:0,SUBTLE_SPRING),pointerEvents:show?'auto':'none'};}"
};
__initData3 = {
code: "function VideoQuestPlayerTsx5(){const{withTiming,progress,timingFast}=this.__closure;return{width:withTiming(progress.get()*100+\"%\",timingFast,'animate-always')};}"
};
const r159 = Module19.memo(function(a0) {
let r420, R3aFPe, children2, children3, props4;
let memo2, state, setState, targetSeconds, c20965_14, c20965_15, state2, setState2, ref2, state3, setState3, ref3, ref4, ref5, ref6, c20965_25, sharedValue, shouldShowControls2, sharedValue2, ref7, handleEndAnalytics, handleErrorAnalytics, handleLoadAnalytics, handleLoadStartAnalytics, handlePausePlaybackAnalytics, handleProgressAnalytics, handleReadyForDisplayAnalytics, handleResumePlaybackAnalytics, handleSeekAnalytics, ref8, id, gameTitle, url, videoTitle, videoStreamType, setState4, callback, callback2, callback3, callback4, c20965_50, ref9, ref10, callback5;
const { style, onLoad, onEnd, onToggleFullscreen, orientation, contentInsets, handleToggleCaptions, handleOpenTranscript, isFullscreen, externallyPaused, captionsEnabled = false, sourceQuestContent } = a0;
let hasCaptionAsset = a0.hasCaptionAsset;
if (hasCaptionAsset === void 0) {
hasCaptionAsset = true;
}
let hasTranscriptAsset = a0.hasTranscriptAsset;
if (hasTranscriptAsset === void 0) {
hasTranscriptAsset = true;
}
memo2 = void 0;
state = void 0;
setState = void 0;
targetSeconds = void 0;
c20965_14 = void 0;
c20965_15 = void 0;
state2 = void 0;
setState2 = void 0;
ref2 = void 0;
state3 = void 0;
setState3 = void 0;
ref3 = void 0;
ref4 = void 0;
ref5 = void 0;
ref6 = void 0;
c20965_25 = void 0;
sharedValue = void 0;
shouldShowControls2 = void 0;
sharedValue2 = void 0;
ref7 = void 0;
handleEndAnalytics = void 0;
handleErrorAnalytics = void 0;
handleLoadAnalytics = void 0;
handleLoadStartAnalytics = void 0;
handlePausePlaybackAnalytics = void 0;
handleProgressAnalytics = void 0;
handleReadyForDisplayAnalytics = void 0;
handleResumePlaybackAnalytics = void 0;
handleSeekAnalytics = void 0;
ref8 = void 0;
id = void 0;
gameTitle = void 0;
url = void 0;
videoTitle = void 0;
videoStreamType = void 0;
setState4 = void 0;
callback = void 0;
callback2 = void 0;
callback3 = void 0;
callback4 = void 0;
c20965_50 = void 0;
ref9 = void 0;
ref10 = void 0;
callback5 = void 0;
const styles = useStyles();
const ref = useRef(null);
const videoQuestModalContext = useVideoQuestModalContext();
const { quest, videoSessionId } = videoQuestModalContext;
const questTaskDetails = useQuestTaskDetails(quest);
let isQuestCompleted = quest.userStatus?.completedAt != null;
let c20965_8 = isQuestCompleted;
const memo = useMemo(() => getQuestAsset(quest, QuestAssetType.VIDEO_PLAYER_VIDEO, void 0, true), [quest]);
memo2 = useMemo(() => getQuestAsset(quest, QuestAssetType.VIDEO_PLAYER_VIDEO_HLS, void 0, true), [quest]);
const videoAssetId = memo2?.url != null ? QuestAssetType.VIDEO_PLAYER_VIDEO_HLS : QuestAssetType.VIDEO_PLAYER_VIDEO;
[state, setState] = useState(questTaskDetails.targetSeconds);
targetSeconds = questTaskDetails.targetSeconds;
const r58 = VideoQuestUIStore((a0) => a0.setVideoProgress);
c20965_14 = r58;
const r45 = VideoQuestUIStore((a0) => {
let r8 = a0.videoProgress[quest.id];
if (r8 == null) {
r8 = {
timestampSec: questTaskDetails.progressSeconds,
duration: state,
maxTimestampSec: questTaskDetails.progressSeconds
};
}
return r8;
}, shallow);
c20965_15 = r45;
[state2, setState2] = useState(PlayerState.LOADING);
ref2 = useRef(false);
let state4;
[state4, setState3] = useState(false);
state3 = state4;
ref3 = useRef(questTaskDetails.progressSeconds);
ref4 = useRef([]);
ref5 = useRef(null);
ref6 = useRef(0);
const isVideoEnded = (state3 ? state2 === PlayerState.ENDED : state3) && r45.timestampSec >= r45.duration - 1;
c20965_25 = isVideoEnded;
sharedValue = useSharedValue(false);
const shouldShowControls = function shouldShowControls() {
let r1 = state3;
if (state3) {
r1 = sharedValue.get() || state2 === PlayerState.PAUSED || state2 === PlayerState.ENDED || state2 === PlayerState.ERRORED || c20965_25 || externallyPaused;
}
return r1;
};
shouldShowControls.__closure = {
hasLoaded: state3,
showControls: sharedValue,
playerState: state2,
PlayerState,
isVideoEnded,
externallyPaused
};
shouldShowControls.__workletHash = 11602236169344;
shouldShowControls.__initData = __initData;
shouldShowControls2 = shouldShowControls;
const G = function G() {
let r5 = state3;
if (state3) {
r5 = sharedValue.get() || state2 === PlayerState.PAUSED || state2 === PlayerState.ENDED || state2 === PlayerState.ERRORED || c20965_25 || externallyPaused;
}
return {
opacity: _spring.withSpring(r5 ? 1 : 0, _springPresets.SUBTLE_SPRING),
pointerEvents: r5 ? "auto" : "none"
};
};
G.__closure = {
shouldShowControls: shouldShowControls2,
withSpring: _spring.withSpring,
SUBTLE_SPRING: _springPresets.SUBTLE_SPRING
};
G.__workletHash = 6174625876255;
G.__initData = __initData2;
const animatedStyle = useAnimatedStyle(G);
if (state3) {
state4 = sharedValue.get() || state2 === PlayerState.PAUSED || state2 === PlayerState.ENDED || state2 === PlayerState.ERRORED || isVideoEnded || externallyPaused;
}
sharedValue2 = useSharedValue(0);
const U = () => ({
width: _timing.withTiming(100 * sharedValue2.get() + "%", _timingPresets.timingFast, "animate-always")
});
U.__closure = {
withTiming: _timing.withTiming,
progress: sharedValue2,
timingFast: _timingPresets.timingFast
};
U.__workletHash = 4647711667921;
U.__initData = __initData3;
const animatedStyle2 = useAnimatedStyle(U);
ref7 = useRef(-1);
const callback6 = useCallback((c27647_0) => function(...args) {
clearTimeout(ref7.current);
sharedValue.set(true);
ref7.current = setTimeout(() => {
sharedValue.set(false);
}, 2000);
if (c27647_0 != null) {
return c27647_0.apply(void 0, [...args]);
}
}, [sharedValue]);
const videoQuestPlayerAnalytics = useVideoQuestPlayerAnalytics({
duration: state,
isQuestCompleted,
playerState: state2,
questId: quest.id,
videoSessionId,
videoAssetId,
sourceQuestContent
});
const handleBufferAnalytics2 = videoQuestPlayerAnalytics.handleBufferAnalytics;
handleEndAnalytics = videoQuestPlayerAnalytics.handleEndAnalytics;
handleErrorAnalytics = videoQuestPlayerAnalytics.handleErrorAnalytics;
handleLoadAnalytics = videoQuestPlayerAnalytics.handleLoadAnalytics;
handleLoadStartAnalytics = videoQuestPlayerAnalytics.handleLoadStartAnalytics;
handlePausePlaybackAnalytics = videoQuestPlayerAnalytics.handlePausePlaybackAnalytics;
handleProgressAnalytics = videoQuestPlayerAnalytics.handleProgressAnalytics;
handleReadyForDisplayAnalytics = videoQuestPlayerAnalytics.handleReadyForDisplayAnalytics;
handleResumePlaybackAnalytics = videoQuestPlayerAnalytics.handleResumePlaybackAnalytics;
handleSeekAnalytics = videoQuestPlayerAnalytics.handleSeekAnalytics;
ref8 = useRef(null);
id = quest.id;
gameTitle = quest.config.messages.gameTitle;
let r64 = memo2?.url;
if (r64 == null) {
r64 = memo?.url;
}
url = r64;
const defaultWatchVideoTask = getDefaultWatchVideoTask(quest.config);
videoTitle = defaultWatchVideoTask == null ? void 0 : defaultWatchVideoTask.messages.videoTitle;
videoStreamType = memo2?.url != null ? "hls" : "mp4";
useEffect(() => {
if (ref.current != null && url != null && url.length !== 0 && getVideoQoEMetricsConfig({
location: QuestsExperimentLocations.VIDEO_MODAL_MOBILE
}).externalAnalyticsEnabled) {
const constants = getConstants();
ref8.current = new MobileMuxWrapper({
videoRef: ref.current,
feature: "quests",
appVersion: constants.Version,
releaseChannel: constants.ReleaseChannel,
contentMetadata: {
contentId: url,
videoStreamType,
contentType: "quests",
durationMs: 1000 * targetSeconds,
title: videoTitle,
questId: id,
gameName: gameTitle
}
});
ref8.current.initialize();
return () => {
if (ref8.current != null) {
ref8.current.onProgress(ref3.current);
ref8.current.destroy();
ref8.current = null;
}
};
}
}, [id, gameTitle, targetSeconds, url, videoTitle, videoStreamType]);
let state5;
[state5, setState4] = useState(false);
const callback7 = useCallback(() => {
handleReadyForDisplayAnalytics();
const current2 = ref8.current;
if (current2 != null) {
current2.onReadyForDisplay();
}
setState4(true);
}, [handleReadyForDisplayAnalytics]);
callback = useCallback((a0) => {
if (ref.current != null) {
const current2 = Math.max(0, Math.min(a0, c20965_15.maxTimestampSec));
if (isAndroid()) {
ref6.current = (ref6.current + 1) % 100;
ref.current.seek(current2 + 0.0001 * ref6.current);
} else {
ref.current.seek(current2);
}
ref5.current = current2;
}
}, [r45.maxTimestampSec]);
const callback8 = useCallback((a0) => {
const { duration, videoTracks, trackId, naturalSize } = a0;
setState(duration);
setState3(true);
handleLoadAnalytics();
const current2 = ref8.current;
if (current2 != null) {
current2.onLoad(duration);
}
if (naturalSize != null) {
const current3 = ref8.current;
if (current3 != null) {
current3.updateVideoSourceDimensions(naturalSize.width, naturalSize.height);
}
}
if (videoTracks != null && videoTracks.length > 0 && trackId != null && trackId.length > 0) {
const current4 = ref8.current;
if (current4 != null) {
current4.onVideoTrackChange(trackId, videoTracks);
}
}
if (ref.current != null) {
const timestampSec = c20965_15.timestampSec;
if ((c20965_8 ? !c20965_8 : timestampSec > 5) && timestampSec < duration - 3) {
callback(timestampSec - 1);
}
setState2(PlayerState.PLAYING);
if (onLoad != null) {
onLoad(a0);
}
}
}, [isQuestCompleted, r45.timestampSec, handleLoadAnalytics, onLoad, callback]);
callback2 = useCallback(function(r3 = {}) {
let shouldRestartVideo = r3.shouldRestartVideo;
if (shouldRestartVideo === void 0) {
shouldRestartVideo = true;
}
L16: {
L14: {
if (state2 !== PlayerState.ERRORED) {
if (c20965_25 && shouldRestartVideo) {
break L14;
}
if (state2 !== PlayerState.PAUSED && state2 !== PlayerState.LOADING) {
if (state2 !== PlayerState.PLAYING) {
break L16;
}
setState2(PlayerState.PAUSED);
handlePausePlaybackAnalytics();
const current2 = ref8.current;
if (current2 == null) {
break L16;
}
current2.onPause();
break L16;
}
setState2(PlayerState.PLAYING);
handleResumePlaybackAnalytics();
const current3 = ref8.current;
if (current3 == null) {
break L16;
}
current3.onPlay();
break L16;
}
}
callback(0);
setState2(PlayerState.PLAYING);
handleResumePlaybackAnalytics();
const current4 = ref8.current;
if (current4 != null) {
current4.onPlay();
}
}
}, [state2, handlePausePlaybackAnalytics, handleResumePlaybackAnalytics, isVideoEnded, callback]);
const callback9 = useCallback(() => callback2(), [callback2]);
callback3 = useCallback(() => {
ref2.current = false;
if (state2 === PlayerState.PLAYING) {
ref2.current = true;
setState2(PlayerState.PAUSED);
handlePausePlaybackAnalytics();
const current2 = ref8.current;
if (current2 != null) {
current2.onPause();
}
}
}, [state2, handlePausePlaybackAnalytics]);
callback4 = useCallback(() => {
if (ref2.current) {
ref2.current = false;
if (state2 !== PlayerState.ERRORED) {
setState2(PlayerState.PLAYING);
handleResumePlaybackAnalytics();
const current2 = ref8.current;
if (current2 != null) {
current2.onPlay();
}
}
}
}, [state2, handleResumePlaybackAnalytics]);
useEffect(() => {
ComponentDispatch.subscribe(ComponentActions.QUEST_GAME_LINK_OPENED, callback3);
ComponentDispatch.subscribe(ComponentActions.QUEST_APP_STORE_OVERLAY_FINISHED, callback4);
return () => {
ComponentDispatch.unsubscribe(ComponentActions.QUEST_GAME_LINK_OPENED, callback3);
ComponentDispatch.unsubscribe(ComponentActions.QUEST_APP_STORE_OVERLAY_FINISHED, callback4);
};
}, [callback3, callback4]);
const callback10 = useCallback(() => {
if (onToggleFullscreen != null) {
onToggleFullscreen({
orientation
});
}
}, [onToggleFullscreen, orientation]);
const callback11 = useCallback(() => {
if (sharedValue.get()) {
sharedValue.set(false);
}
callback2({
shouldRestartVideo: false
});
}, [sharedValue, callback2]);
const callback12 = useCallback((a0) => {
let r7 = ref4.current.shift();
if (r7 == null) {
r7 = null;
}
if (ref.current != null) {
ref3.current = a0.currentTime;
ref5.current = null;
if (state > 0) {
sharedValue2.set(a0.currentTime / state);
c20965_14(quest.id, a0.currentTime, state);
}
handleSeekAnalytics(r7, a0.currentTime);
const current2 = ref8.current;
if (current2 != null) {
current2.updatePlayheadTime(a0.currentTime);
}
const current3 = ref8.current;
if (current3 != null) {
current3.onSeek();
}
}
}, [state, sharedValue2, handleSeekAnalytics, quest.id, r58]);
let disabled = state2 === PlayerState.ERRORED;
if (!disabled) {
const { timestampSec, maxTimestampSec } = r45;
const r10 = timestampSec >= r45.duration - 1;
let r8 = !r10;
if (!r10) {
if (!isQuestCompleted) {
isQuestCompleted = timestampSec <= maxTimestampSec - 1;
}
r8 = isQuestCompleted;
}
disabled = !r8;
}
c20965_50 = disabled;
const callback13 = useCallback(() => {
if (!c20965_50) {
let current2 = ref5.current;
if (current2 == null) {
current2 = sharedValue2.get() * state;
}
ref4.current.push(current2);
callback(current2 + 10);
}
}, [callback, state, sharedValue2, disabled]);
const onPress = callback6(useCallback(() => {
let current2 = ref5.current;
if (current2 == null) {
current2 = sharedValue2.get() * state;
}
ref4.current.push(current2);
callback(current2 - 10);
if (state2 === PlayerState.ENDED) {
setState2(PlayerState.PLAYING);
}
}, [callback, state, sharedValue2, state2]));
const onPress2 = callback6(callback13);
ref9 = useRef(0);
ref10 = useRef(0);
const callback14 = useCallback((a0) => {
const r7 = a0.seekableDuration !== 0 ? a0.currentTime / a0.seekableDuration : 0;
ref3.current = a0.currentTime;
if (a0.currentTime >= ref9.current) {
sendVideoProgress(quest, a0.currentTime);
handleProgressAnalytics(r7, a0.seekableDuration, a0.currentTime);
ref9.current = a0.currentTime + 6 + 2 * Math.random();
}
if (a0.currentTime >= ref10.current) {
updateOptimisticProgress(quest.id, questTaskDetails.taskType, a0.currentTime);
ref10.current = a0.currentTime + 1;
}
c20965_14(quest.id, a0.currentTime, a0.seekableDuration);
sharedValue2.set(r7);
const current2 = ref8.current;
if (current2 != null) {
current2.onProgress(a0.currentTime);
}
}, [sharedValue2, quest, ref9, ref10, questTaskDetails.taskType, r58, handleProgressAnalytics]);
const callback15 = useCallback(() => {
sendVideoProgress(quest, state);
handleEndAnalytics();
setState2(PlayerState.ENDED);
const current2 = ref8.current;
if (current2 != null) {
current2.onProgress(state);
}
const current3 = ref8.current;
if (current3 != null) {
current3.onEnd();
}
if (onEnd != null) {
onEnd();
}
}, [state, quest, handleEndAnalytics, onEnd]);
const callback16 = useCallback(() => {
setState2(PlayerState.LOADING);
handleLoadStartAnalytics();
const current2 = ref8.current;
if (current2 != null) {
current2.onLoadStart();
}
const current3 = ref8.current;
if (current3 != null) {
current3.onPlay();
}
}, [handleLoadStartAnalytics]);
const callback17 = useCallback((a0) => {
setState2(PlayerState.ERRORED);
handleErrorAnalytics(a0);
const current2 = ref8.current;
if (current2 != null) {
current2.onError(a0);
}
}, [handleErrorAnalytics]);
const callback18 = useCallback((a0) => {
if (a0 != null && a0.videoTracks != null && a0.videoTracks.length > 0 && a0.selectedVideoTrackId != null && a0.selectedVideoTrackId.length > 0) {
const current2 = ref8.current;
if (current2 != null) {
current2.onVideoTrackChange(a0.selectedVideoTrackId, a0.videoTracks);
}
}
}, []);
const callback19 = useCallback((a0) => {
if ((a0 == null ? void 0 : a0.nativeEvent?.layout) != null) {
const layout = a0.nativeEvent.layout;
const { width, height } = layout;
if (width > 0 && height > 0) {
const current2 = ref8.current;
if (current2 != null) {
current2.updateVideoDimensions(width, height);
}
}
}
}, []);
const r320 = useStateFromStores([AppStateStore], () => AppStateStore.getState()) === AppStates.ACTIVE;
const memo3 = useMemo(() => {
const r1 = memo == null;
let r2 = null;
if (!r1) {
let uri = memo2?.url;
if (uri == null) {
uri = memo.url;
}
r2 = {
uri
};
}
return r2;
}, [memo2, memo]);
useLayoutEffect(() => {
if (isAndroid()) {
const current = ref.current;
return () => {
try {
if (current != null) {
const setNativeProps = current.setNativeProps;
if (setNativeProps != null) {
setNativeProps.call(current, {
paused: true,
src: {
uri: null
}
});
}
}
} catch ($e) {
SentryUtils_native.captureException($e);
}
};
}
}, []);
const paused = (r320 ? state2 === PlayerState.PAUSED : !r320) || state2 === PlayerState.LOADING || externallyPaused;
const handleBufferAnalytics = handleBufferAnalytics2;
const ref11 = ref8;
const ref12 = useRef(false);
let [state6, setState5] = useState(false);
callback5 = useCallback((a0) => {
setState5(a0);
if (a0 !== ref12.current) {
ref12.current = a0;
handleBufferAnalytics(a0);
const current2 = ref11.current;
if (current2 != null) {
current2.onBuffer(a0);
}
}
}, [handleBufferAnalytics, ref8]);
const callback20 = useCallback((a0) => {
let isBuffering;
L6: {
L4: {
isBuffering = a0.isBuffering;
if (isBuffering) {
if (state2 !== PlayerState.LOADING && isIOS()) {
break L4;
}
callback5(true);
break L6;
}
}
if (!isBuffering) {
callback5(false);
}
}
}, [callback5, state2]);
const callback21 = useCallback(() => {
if (isIOS()) {
callback5(true);
}
}, [callback5]);
const callback22 = useCallback(() => {
if (isIOS()) {
callback5(false);
}
}, [callback5]);
const safeAreaInsets_native = useSafeAreaInsets_native();
if (memo3 == null) {
return null;
}
const r359 = isFullscreen && safeAreaInsets_native != null && {
paddingRight: Math.max(safeAreaInsets_native.right, c9911_15.right),
paddingLeft: Math.max(safeAreaInsets_native.left, c9911_15.left)
};
const props = {
style: [styles.container, style],
accessible: false,
children: null
};
const props2 = {
style: [styles.videoContainer],
onPress: callback11,
accessible: !state4,
accessibilityLabel: intl.string(paused ? t.R3aFPe : t.fTMEUi),
children: null
};
const children = [state2 !== PlayerState.ERRORED && <Component mixWithOthers="inherit" ref={ref} accessible={false} importantForAccessibility="no-hide-descendants" accessibilityRole="none" style={styles.video} paused={paused} source={memo3} onBuffer={callback20} onPlaybackStalled={callback21} onPlaybackResume={callback22} onLoad={callback8} onSeek={callback12} onProgress={callback14} onLoadStart={callback16} onEnd={callback15} onError={callback17} onReadyForDisplay={callback7} onVideoTracks={callback18} onLayout={callback19} resizeMode="contain" />, , , , , ,];
let top = contentInsets?.top;
if (top == null) {
top = 0;
}
let bottom = contentInsets?.bottom;
if (bottom == null) {
bottom = 0;
}
let left = contentInsets?.left;
if (left == null) {
left = 0;
}
let right = contentInsets?.right;
if (right == null) {
right = 0;
}
children[1] = <VideoQuestCaptions quest={quest} currentTime={r45.timestampSec} visible={captionsEnabled} style={{
top,
bottom,
left,
right
}} />;
if (state6) {
const style2 = [styles.bufferingSpinner, ,];
if (!isFullscreen && orientation !== "landscape") {
let top2 = contentInsets?.top;
if (top2 == null) {
top2 = 0;
}
let left2 = contentInsets?.left;
if (left2 == null) {
left2 = 0;
}
r420 = {
top: top2,
left: left2
};
} else {
r420 = styles.bufferingSpinnerCentered;
}
style2[1] = r420;
state6 = <ActivityIndicator animating style={style2} color={Module712.unsafe_rawColors.WHITE} />;
}
children[2] = state6;
children[3] = state5 ? !state5 : <View style={styles.loadingContainer}>
<ActivityIndicator animating />
</View>;
const props3 = {
style: [styles.controls, animatedStyle],
accessible: false,
children: null
};
let r441 = orientation === "landscape";
let r442 = r441;
if (r441) {
if (hasCaptionAsset) {
hasCaptionAsset = <PressableOpacity accessibilityRole="button" accessibilityLabel={intl.string(t.bDSZO1)} onPress={handleToggleCaptions} style={styles.controlButton}>
<ClosedCaptionsOutlineIcon color={captionsEnabled ? styles.icon.color : styles.iconDisabled.color} />
</PressableOpacity>;
}
const r469 = [hasCaptionAsset, ,];
if (hasTranscriptAsset) {
hasTranscriptAsset = <PressableOpacity accessibilityRole="button" accessibilityLabel={intl.string(t.KCzjTi)} onPress={handleOpenTranscript} style={styles.controlButton}>
<TranscriptOutlineIcon color={styles.iconDisabled.color} />
</PressableOpacity>;
}
r469[1] = hasTranscriptAsset;
r442 = <View style={[styles.controlsTopBottom, styles.controlsTop, r359]}>{r469}</View>;
}
L117: {
children2 = [r442, , ,];
props4 = {
style: styles.controlsMiddle,
children: null
};
children3 = [<VideoQuestPlayerControlButton disabled={state2 === PlayerState.ERRORED} accessibilityRole="button" accessibilityLabel={intl.string(t.r9s3Uv)} onPress={onPress}>
<SkipBackwardIcon color={styles.icon.color} width={16} height={16} />
</VideoQuestPlayerControlButton>, , ,];
if (!isVideoEnded && state2 !== PlayerState.ERRORED) {
if (paused) {
R3aFPe = t.R3aFPe;
break L117;
}
R3aFPe = t.fTMEUi;
} else {
R3aFPe = t.K0e7M9;
}
}
children3[1] = <VideoQuestPlayerControlButton accessibilityRole="button" accessibilityLabel={intl.string(R3aFPe)} onPress={callback9}>
{!isVideoEnded && state2 !== PlayerState.ERRORED ? paused ? <PlayIcon size="lg" /> : <PauseIcon size="lg" /> : <RetryIcon size="lg" />}
</VideoQuestPlayerControlButton>;
children3[2] = <VideoQuestPlayerControlButton disabled={disabled} accessibilityRole="button" accessibilityLabel={intl.string(t.zWDcNP)} onPress={onPress2}>
<SkipForwardIcon color={styles.icon.color} width={16} height={16} />
</VideoQuestPlayerControlButton>;
props4.children = children3;
children2[1] = <View {...props4} />;
children2[2] = r441 ? <View style={[styles.controlsTopBottom, styles.controlsBottom, r359]}>
<PressableOpacity accessibilityRole="button" accessibilityLabel={intl.string(t.vKZT5t)} onPress={callback10} style={styles.controlButton}>
<FullscreenEnterIcon />
</PressableOpacity>
</View> : r441;
props3.children = children2;
children[4] = <ReanimatedRexport.View {...props3} />;
if (r441) {
r441 = <View style={styles.progressContainer}>
<ReanimatedRexport.View style={[styles.progress, animatedStyle2]} />
</View>;
}
children[5] = r441;
props2.children = children;
props.children = <Pressable {...props2} />;
return <View {...props} />;
});
exports.PlayerState = PlayerState;
export { r159 as VideoQuestPlayer };