Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/src/VideoPlayerExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const VideoPlayerExample: React.FC = () => {
ref={videoPlayerRef}
style={{ width: 350, height: 250 }}
source={{
uri: "https://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4",
uri: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
}}
useNativeControls={false}
posterSource={{
uri: "https://fujifilm-x.com/wp-content/uploads/2021/01/gfx100s_sample_04_thum-1.jpg",
uri: "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg",
}}
usePoster
onPlaybackStatusUpdate={(status) => setPlayerState(status)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
AVPlaybackStatus,
VideoFullscreenUpdate,
AVPlaybackSource,
Audio,
} from "expo-av";
import { extractSizeStyles } from "../../../utilities";
import MediaPlaybackWrapper from "../MediaPlaybackWrapper";
Expand All @@ -27,6 +28,7 @@ type ExpoVideoPropsOmitted = Omit<
interface VideoPlayerProps extends ExpoVideoPropsOmitted, MediaPlayerProps {
resizeMode?: ResizeMode;
posterResizeMode?: ImageResizeMode;
playsInSilentModeIOS?: boolean;
}

export interface VideoPlayerRef extends MediaPlayerRef {
Expand All @@ -42,6 +44,7 @@ const VideoPlayer = React.forwardRef<VideoPlayerRef, VideoPlayerProps>(
onPlaybackStatusUpdate: onPlaybackStatusUpdateProp,
onPlaybackFinish,
source,
playsInSilentModeIOS = false,
...rest
},
ref
Expand Down Expand Up @@ -102,6 +105,20 @@ const VideoPlayer = React.forwardRef<VideoPlayerRef, VideoPlayerProps>(
}
}, [isFullscreen, videoMediaObject]);

const updateAudioMode = React.useCallback(async () => {
try {
await Audio.setAudioModeAsync({
playsInSilentModeIOS,
});
} catch (e) {
console.error("Failed to set audio mode. Error details:", e);
}
}, [playsInSilentModeIOS]);

React.useEffect(() => {
updateAudioMode();
}, [updateAudioMode]);

React.useImperativeHandle(
ref,
() => ({
Expand Down Expand Up @@ -131,6 +148,7 @@ const VideoPlayer = React.forwardRef<VideoPlayerRef, VideoPlayerProps>(
media={videoMediaObject as Playback | undefined}
isPlaying={isPlaying}
ref={mediaPlaybackWrapperRef}
onTogglePlayback={updateAudioMode}
>
<VideoPlayerComponent
// https://docs.expo.dev/versions/latest/sdk/av/#example-video to see why ref is handled this way
Expand Down