I am using react-native-video package to get video player in which i can play my youtube videos.
I tried this but only a empty space was coming instead of a video player.
import Video from 'react-native-video';
<Video source={{uri: 'https://www.youtube.com/watch?v=Gh2FaDqZp2g'}}
ref={(ref) => {
this.player = ref
}}
onBuffer={this.onBuffer}
onEnd={this.onEnd}
onError={this.videoError}
style={styles.backgroundVideo} />
style:
backgroundVideo: {
height:300,
width:'100%',
}
I think Video tag will accept Uri ending with .mp4 format..
Please replace your uri with this http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4
(Note: Some other uri can also be used with same format) and checkout.
But for streaming Youtube videos you will have to use react-native-youtube and Youtube API Component.
Please refer this link for further
I see there some problems in your code:
1/ uri: please replace by this link: "http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4"
source={{uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'}}
2/ Your style: as I remember width: '100%
does not work, you should set it to a specific number. Or you can make video container view wraps the video view
<View style={styles.videoContainer}>
<Video
source={{uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'}}
ref={(ref) => {
this._player = ref
}}
...
style={styles.video}/>
</View>
View style:
videoContainer: {
flex: 1,
backgroundColor: 'black',
},
video: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
},
Hope this can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With