gpt4 book ai didi

react-native - 如何在 React Native 中自动播放 youtube 嵌入的视频?

转载 作者:行者123 更新时间:2023-12-04 02:28:59 34 4
gpt4 key购买 nike

我正在尝试在我的 native 应用程序中自动播放 youtube 嵌入的视频。

这是我的代码,

render() {
const { data } = this.props;
const { loading } = this.state;
return (
<View>
<CloseButton onTrigger={this.closeModal.bind(this)} />
<PlayIcon onTrigger={this.playVideo} />
<Image source={{uri:data.src}} resize='contain' style={{height:250}} />
<Image
source={require('../../assets/img/grediant.png')}
resizeMode='cover' style={styles.gradientImage} />
<ContentWidget style={styles.infoContentTwo}>
<MyAppText style={{color:'white'}}>{data.title}</MyAppText>
</ContentWidget>
{this.state.openVideo && <View style={styles.webViewStyle}>
<WebView style={{height:250}} source={{uri:`${data.video}?autoplay=1`}} fullScreen={true} />
</View>}
{loading && <Spinner />}
</View>
);
}

但它不起作用,我有一个 playIcon 自定义按钮,如果我单击该按钮,则应播放 youtube 视频。我不知道我在代码中哪里错了。

最佳答案

您可以使用 react-native-youtube 将 youtube 视频嵌入到您的 native 项目中。您可以配置该属性以自动播放视频。

<YouTube
videoId="KVZ-P-ZI6W4" // The YouTube video ID
play={true} // control playback of video with true/false
onReady={e => this.setState({ isReady: true })}
onChangeState={e => this.setState({ status: e.state })}
onChangeQuality={e => this.setState({ quality: e.quality })}
onError={e => this.setState({ error: e.error })}
style={{ alignSelf: 'stretch', height: 300 }}
/>

关于react-native - 如何在 React Native 中自动播放 youtube 嵌入的视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49187085/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com