barmej / react-native-youtube-player

A Cross-platform Youtube Player component for React Native Built using the official YouTube IFrame Player API.
128 stars 49 forks source link

Great Tutorial #5

Closed jkdobariya7 closed 5 years ago

jkdobariya7 commented 5 years ago

Please give me example how to change video height and width in custom view and as well as give me example how to work with seek change.

yjose commented 5 years ago

Hi @jkdobariya7 , you can easily use seekTo function from player ref to handle seek change like the following

import React, { Component } from "react";
import { Platform, StyleSheet, Text, View } from "react-native";
import YoutubePlayer from "react-native-yt-player";

export default class App extends Component<Props> {

  play = () => {
    this.player.playVideo();
  };
  pause = () => {
    this.player.pauseVideo();
  };

  seekTo = s => {
    this.player.seekTo(s);
  };
  render() {
    return (
      <View style={{ paddingTop: 60 }}>
        <YoutubePlayer
          loop
          ref={ref => {
            this.player = ref;
          }}
          topBar={TopBar}
          videoId="Z1LmpiIGYNs"
          autoPlay
          onFullScreen={this.onFullScreen}
          onStart={() => console.log("onStart")}
          onEnd={() => alert("on End")}
        />
      </View>
    );
  }
}

Unfortunately ( for now) we are using 16:9 static aspect ratio to calculate video height and width see : https://github.com/barmej/react-native-youtube-player/blob/master/src/mobile/Utils.tsx#L11