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

Thumb Jumps to 0 when Slider value is being set programmatically when updated by expo-av #679

Open
Gata-chan opened this issue Jan 9, 2025 · 0 comments

Comments

@Gata-chan
Copy link

Versions

Expo: ~51.0.17
Expo-av: ~14.0.6
React: 18.2.0
React-Native: 0.74.3
@react-native-community/slider: 4.5.2

Demonstration

https://drive.google.com/file/d/1A3suBjpINpGPBf7SGFsFvMffCd_lVz6e/view?usp=sharing

Implementation

This is not exact code as-is in the app, just the bits that matter

SoundControlContext.js

import Slider from "@react-native-community/slider";
import { useSound } from './SoundProvider.js';

    const {soundDuration,  positionMillis, handleSoundPan} = useSound()

    const handleSliding = async (value) => {
            handleSoundPan(value)
        }

<Slider onSlidingComplete={(value) => {handleSliding(value)}}
            style={{width: '75%', height: 32}} 
            minimumValue={0} 
            maximumValue={soundDuration }
            value={ positionMillis }
            thumbTintColor="#F7F7FF"
            minimumTrackTintColor="#F7F7FF"
            maximumTrackTintColor="#dcdce6"/>

SoundProvider.js

import { Audio } from "expo-av";

const sound = useRef(new Audio.Sound())
const [positionMillis, setPositionMillis] = useState(0);

sound.current.setOnPlaybackStatusUpdate((status) => {
                handleSoundStatus(status)
            })
await sound.current.setProgressUpdateIntervalAsync(1000)

const handleSoundPan = async (position) => {
        await sound.current.setPositionAsync(position)
    }

const handleSoundStatus = async (status) => {
        if (status.durationMillis != soundDuration || soundDuration == 0) {
          setSoundDuration(await status.durationMillis)  
        }
        
       
        setPositionMillis(await status.positionMillis)
....
}

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

No branches or pull requests

1 participant