Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seek Issue : Not Able to seek from slider change #229

Open
PervezBellary opened this issue Jan 20, 2025 · 1 comment
Open

Seek Issue : Not Able to seek from slider change #229

PervezBellary opened this issue Jan 20, 2025 · 1 comment
Labels
question Further information is requested

Comments

@PervezBellary
Copy link

// trying to seek from slider change but the video is restarting

import React, { useState, useRef } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { VLCPlayer } from 'react-native-vlc-media-player';
import Slider from '@react-native-community/slider';

const VideoPlayer = ({ url }) => {
const videoRef = useRef(null);
const [isPlaying, setIsPlaying] = useState(true);
const [isMuted, setIsMuted] = useState(false);
const [duration, setDuration] = useState(0);
const [currentTime, setCurrentTime] = useState(0);

const handleProgress = ({ currentTime, position }) => {
if (!isNaN(currentTime)) {
setCurrentTime(currentTime);
}
};

const handleSliderChange = (value) => {
setCurrentTime(value);
};

const handlePlayPause = () => {
setIsPlaying(!isPlaying);
};

const handleMuteUnmute = () => {
setIsMuted(!isMuted);
};

const handleOnPlaying = ({ duration }) => {
setDuration(duration);
};

const onSlidingComplete = (value) => {
if (videoRef.current && duration > 0) {
const seekTime = value / 1000;
videoRef.current.seek(seekTime);
}
};

return (

<VLCPlayer
ref={videoRef}
style={styles.videoPlayer}
source={{ uri: url }}
paused={!isPlaying}
muted={isMuted}
onProgress={handleProgress}
onPlaying={handleOnPlaying}
onError={(error) => console.log('ERROR', error)}
/>
<Slider
style={styles.slider}
minimumValue={0}
maximumValue={duration * 1000}
value={currentTime * 1000}
onSlidingComplete={onSlidingComplete}
onValueChange={handleSliderChange}
minimumTrackTintColor="#1FB6FF"
maximumTrackTintColor="#d3d3d3"
thumbTintColor="#1FB6FF"
/>


{isPlaying ? 'Pause' : 'Play'}


{isMuted ? 'Unmute' : 'Mute'}



);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
videoPlayer: {
width: '100%',
height: 300,
},
slider: {
width: '100%',
height: 40,
marginTop: 10,
},
controls: {
marginTop: 10,
},
});

export {VideoPlayer}

@cornejobarraza cornejobarraza added the question Further information is requested label Jan 22, 2025
@cornejobarraza
Copy link
Collaborator

Is this issue happening on Android, iOS or both? Do you have a reproducible example repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants