Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native-video not showing the video player

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%',
  }
like image 702
Eshant Bist Avatar asked Sep 26 '18 05:09

Eshant Bist


Video Answer


2 Answers

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

like image 86
Sandy Avatar answered Oct 07 '22 00:10

Sandy


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.

like image 1
Luong Truong Avatar answered Oct 06 '22 23:10

Luong Truong