我使用react native track player。我想从ProgressComponent获取跟踪的位置并更新应用上下文的状态。
使用react上下文可以在其他组件中工作,但不能正常工作。 如何在该组件中使用ract上下文?
myCode
import React , { useState, useContext } from 'react'
import {View, Text} from 'react-native'
import {ProgressComponent , useTrackPlayerProgress} from 'react-native-track-player';
import Slider from '@react-native-community/slider';
import PlayerContext from './PlayerContext'
export default class SourcePlayer extends ProgressComponent {
render() {
return (
<Progress />
);
}
}
const Progress = () => {
const { position, bufferedPosition, duration } = useTrackPlayerProgress();
return (
<View>
<Slider
minimumValue={0}
maximumValue={duration}
value={position}
/>
<View>
<Text>{position}</Text>
</View>
</View>
)
}