We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
// 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}
The text was updated successfully, but these errors were encountered:
Is this issue happening on Android, iOS or both? Do you have a reproducible example repository?
Sorry, something went wrong.
No branches or pull requests
// 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}
The text was updated successfully, but these errors were encountered: