Home > Software design >  react-native-video auto repeat issue on IOS
react-native-video auto repeat issue on IOS

Time:12-17

I am developing react native app that show video. I have used react-native-video package. When the video page open, the video will auto start for once and should not repeat after the video end. It works well on android but on IOS the video auto start again from the beginning and keep repeating. This is my code to stop video after the video end:

  const onEnd = () => {
   setState({ ...state, play: false, showControls: true });
   if (videoRef.current) {
     videoRef.current.seek(0);
   }
  };

How I can solve this issue?

CodePudding user response:

Determine whether to repeat the video when the end is reached

false (default) - Don't repeat the video true - Repeat the video

The simplest way to do this

<Video
      onEnd={() => {
      this._video.seek(0);
      this.setState({ pauseVideo: !this.state.pauseVideo })
      }}
      repeat={false}
      paused={this.state.pauseVideo}
      key={(item, index) => index.toString()}
      source={{ uri:"url" }}
      onBuffer={(data) => {
           if (data.isBuffering) {
             this.setState({ loading: true });
           } else {
             this.setState({ loading: false });
           }
           }}
      onl oad={() => this.setState({ loading: false })}
      onl oadStart={() => this.setState({ loading: true })}
      resizeMode="contain"
      style={{ height: "100%", width: "100%" }}/>

ios/Video/RCTVideo.m

        [item seekToTime:kCMTimeZero];
        [self applyModifiers];
      } else {
        [self setPaused:true]; //`add this line to RCTVideo.m`
        [self removePlayerTimeObserver];
      }
    }

CodePudding user response:

I solved it by removing this line of my code. Keep current video time at maximum duration and don't set to 0, it will make infinite repeat condition.

if (videoRef.current) {
 videoRef.current.seek(0);
}
  • Related