react-native-vlc-media-player icon indicating copy to clipboard operation
react-native-vlc-media-player copied to clipboard

Repeat is working only once when using player in flatlist

Open Kadir-prog opened this issue 2 years ago • 3 comments

hi i am trying to repeat my current video multiple times currently I'm using repeat prop but its working only on one video i had 5 videos in my faltlist and played one at a time

expected behavior

  1. video should play continously after video finished

please help

Kadir-prog avatar Sep 26 '23 08:09 Kadir-prog

@Kadir-prog Did you implemented?

sraza295 avatar Dec 15 '23 11:12 sraza295

I have the same problem repeat doesn't work

bakirnewfire avatar Dec 15 '23 16:12 bakirnewfire

I have the same problem repeat doesn't work @bakirnewfire @Kadir-prog I have fixed it.

import React, { Component } from 'react'; import { View } from 'react-native'; import VLCPlayer from 'react-native-vlc-player';

class YourComponent extends Component { constructor(props) { super(props); this.state = { // Your existing state variables // ... key: 1, // Add a key to force remounting of the VLCPlayer component }; }

onEnded() { // Seek to the beginning this.playerRef.seek(0);

// Use setTimeout to ensure that seeking is complete before remounting the component
setTimeout(() => {
  // Increment the key to force remounting of the VLCPlayer component
  this.setState((prevState) => ({ key: prevState.key + 1 }));
}, 100);

}

render() { return ( <View> {/* Force remounting by changing the key */} <VLCPlayer key={this.state.key} style={{ width: this.state.width, height: this.state.Fullscreen ? this.state.orientation_change_height : '100%', }} autoplay={true} videoAspectRatio="16:9" resizeMode="fill" muted={this.state.muted} repeat={true} ref={(ref) => (this.playerRef = ref)} paused={this.state.paused} onProgress={this.progress} onEnd={this.onEnded.bind(this)} onBuffering={this.onBuffering.bind(this)} onError={this._onError} onStopped={this.onStopped.bind(this)} onPlaying={this.onPlaying.bind(this)} onPaused={this.onPaused.bind(this)} onLoad={this.load} source={{ uri: this.state.video_uri_path, initType: 2, initOptions: ['--rtsp-tcp', '--no-stats'], }} /> </View> ); } }

export default YourComponent;

sraza295 avatar Dec 15 '23 17:12 sraza295