我在我的 react-native 应用程序中使用react-native-video 。我希望能够动态更改视频源,但发现它并不容易。我的方法是简单地通过使用钩子更改剪辑名称,将 video1 更改为 video2。但我无法更新视频实例:
我确实尝试过这样的事情:
const [clipSelected, setClipSelected] = useState('video1');
const onButton = (name) => {
console.log("videoname", name)
setClipSelected(name);
}
return (
<Fragment>
<View style={styles.container}>
<Video
source={require('./' + clipSelected + '.mp4')}
ref={(ref) => {
bgVideo = ref
}}
onBuffer={this.onBuffer}
onError={this.videoError}
rate={1}
repeat={true}
/>
<Button onPress={(e) => onButton('video2')}></Button>
</View>
</Fragment >
);
是否有任何其他人知道我可以在哪里解决这个问题的库、方法或方法?基本上是一种更新视频源实例的方法。我要在 Android TV 上运行它...