kha*_*hul 11 youtube autoplay react-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>
);
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我有一个playIcon自定义按钮,如果我点击该按钮,那么youtube视频应播放.我不知道代码中哪里出错了.
小智 1
您可以使用react-native-youtube将youtube视频嵌入到您的react 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 }}
/>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1397 次 |
| 最近记录: |