The "Unhandled promise rejection: Error: Seeking interrupted." error in React Native's Expo Video AV module typically occurs when there is a conflict or interruption during the process of seeking (jumping to a specific time) in a video playback.

This error can be triggered by various factors, such as:

  1. Invalid Seek Time: Attempting to seek to an invalid time position in the video.
  2. Multiple Simultaneous Seeks: Triggering multiple seek requests in rapid succession.
  3. Video Unloaded or Not Ready: Trying to seek before the video has fully loaded or is not yet ready for seeking.

To resolve this issue, you can implement proper error handling and check the readiness of the video before performing any seek operation. Here's an example of how to handle the error and ensure the video is ready for seeking:

javascript
import React, { useRef, useState } from 'react'; import { Video } from 'expo-av'; import { View, Button } from 'react-native'; const VideoPlayer = () => { const videoRef = useRef(null); const [isVideoReady, setIsVideoReady] = useState(false); const handleOnLoad = () => { setIsVideoReady(true); }; const handleSeek = async () => { if (!isVideoReady) { // Video is not ready for seeking, handle it gracefully or show a message. return; } try { // Get the duration of the video const { durationMillis } = await videoRef.current.getStatusAsync(); // Seek to a specific time position (in this example, seeking to 10 seconds) await videoRef.current.setPositionAsync(10000); } catch (error) { console.error('Error seeking video:', error); } }; return ( <View> <Video ref={videoRef} source={{ uri: 'path/to/your/video.mp4' }} useNativeControls onPlaybackStatusUpdate={(status) => { // Handle playback status updates here if needed }} onLoad={handleOnLoad} /> <Button title="Seek to 10 seconds" onPress={handleSeek} /> </View> ); }; export default VideoPlayer;

In the above example, we use the isVideoReady state variable to track whether the video is fully loaded and ready for seeking. The handleOnLoad function is called when the video has loaded successfully, and it sets the isVideoReady state to true.

When the "Seek to 10 seconds" button is pressed, the handleSeek function checks if the video is ready for seeking (isVideoReady is true) before attempting to seek to the desired time position.

By implementing proper error handling and checking the video's readiness, you can prevent the "Unhandled promise rejection: Error: Seeking interrupted." error from occurring in your Expo Video AV component in React Native.

Have questions or queries?
Get in Touch