Coder Social home page Coder Social logo

barmej / react-native-youtube-player Goto Github PK

View Code? Open in Web Editor NEW
125.0 3.0 49.0 6.8 MB

A Cross-platform Youtube Player component for React Native Built using the official YouTube IFrame Player API.

JavaScript 9.71% Java 9.77% Objective-C 6.90% TypeScript 63.72% HTML 0.61% Starlark 0.95% Ruby 8.34%

react-native-youtube-player's Introduction

React Native Youtube Player

A cross-platform Youtube Player component for React Native Built using the official YouTube IFrame Player API.

Features

  • No need of API key
  • FullScreen Animation
  • FullScreen on orientation change.
  • Full Control
  • Add Custom TopBar
  • Fully typed with TypeScript

DEMO

  • Checkout the example/ folder for demo source code.

Demo

Installation

Open a Terminal in the project root and run:

yarn add react-native-yt-player
yarn add react-native-webview
yarn add @react-native-community/slider
yarn add react-native-reanimated
yarn add react-native-orientation

Link react-native-webview, react-native-slider,react-native-orientation and react-native-reanimated:

react-native link react-native-webview
react-native link @react-native-community/slider
react-native link react-native-reanimated
react-native link react-native-orientation

IMPORTANT: There are additional steps required for react-native-orientation on Android after running react-native link react-native-orientation. Check the this guide to complete the installation.

Quick Start

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> {
  onFullScreen = fullScreen => {
    console.log("fullscreen ", fullScreen);
  };
  render() {
    return (
      <View style={{ paddingTop: 60 }}>
        <YoutubePlayer
          loop
          topBar={TopBar}
          videoId="Z1LmpiIGYNs"
          autoPlay
          onFullScreen={this.onFullScreen}
          onStart={() => console.log("onStart")}
          onEnd={() => alert("on End")}
        />

        <View>
          <Text>
            Lorem, ipsum dolor sit amet consectetur adipisicing elit. Commodi,
            aspernatur rerum, deserunt cumque ipsam unde nam voluptatum tenetur
            cupiditate veritatis autem quidem ad repudiandae sapiente odit
            voluptates fugit placeat ut!
          </Text>
        </View>
      </View>
    );
  }
}

const TopBar = ({ play, fullScreen }) => (
  <View
    style={{
      alignSelf: "center",
      position: "absolute",
      top: 0
    }}
  >
    <Text style={{ color: "#FFF" }}> Custom Top bar</Text>
  </View>
);

API reference

Property Type Description
videoId(required) string Youtube video Id
autoPlay Boolean Auto play the video
loop Boolean Loop the video
style object You can pass this to override some default styles
topBar (play: boolean, fullScreen: boolean) => React.ReactNode Function which takes the play and fullScreen status and return a react element to be used as a topBar
showFullScreenButton Boolean Display a button to allow user to see the video on fullScreen
onFullScreen (fullScreen: Boolean) => void Execute a function on fullScreen changed
onStart () => void Execute a function on start
onPause () => void Execute a function on pause
onDurationReady (s: number) => void Execute a function when the duration is ready
onPlaybackRateChange () =>void Execute a function when the playback rate will actually change
onEnd () => void Execute a function on end
onError () => void Execute a function on error

Check types.tsx file.

You can use Ref to access to Player functions in case you want to have full control :

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> {
  onFullScreen = fullScreen => {
    console.log("fullscreen ", fullScreen);
  };

  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>
          <Text>
            Lorem, ipsum dolor sit amet consectetur adipisicing elit. Commodi,
            aspernatur rerum, deserunt cumque ipsam unde nam voluptatum tenetur
            cupiditate veritatis autem quidem ad repudiandae sapiente odit
            voluptates fugit placeat ut!
          </Text>
        </View>
      </View>
    );
  }
}

const TopBar = ({ play, fullScreen }) => (
  <View
    style={{
      alignSelf: "center",
      position: "absolute",
      top: 0
    }}
  >
    <Text style={{ color: "#FFF" }}> Custom Top bar</Text>
  </View>
);

Licensing

The code in this project is licensed under MIT license.

Credit

react-native-webview-invoke For Making Communication between react-native and webview simple and clean.

react-native-tab-view For the great Project structure.

react-native-youtube-player's People

Contributors

brendonsled avatar dependabot[bot] avatar smakosh avatar yassir4 avatar yjose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-youtube-player's Issues

Control panel buttons don't work...

Hello! Please, would you help to find the reason why control panel buttons doesn't work at all... Play, pause, fullscreen - no one of them. I've rechecked instalation manual twice and seems everything is correct.
My 'package.json':
"dependencies": {
"@react-native-community/async-storage": "^1.8.0",
"@react-native-community/masked-view": "^0.1.6",
"@react-native-community/slider": "^1.1.2",
"axios": "^0.19.2",
"install": "^0.13.0",
"jetifier": "^1.6.5",
"moment": "^2.24.0",
"native-base": "^2.13.8",
"npm": "^6.13.7",
"react": "16.8.3",
"react-native": "0.59.8",
"react-native-device-info": "^5.5.3",
"react-native-fbsdk": "^1.1.2",
"react-native-gesture-handler": "^1.6.0",
"react-native-google-signin": "^2.1.1",
"react-native-linear-gradient": "^2.5.6",
"react-native-orientation": "^3.1.3",
"react-native-reanimated": "^1.7.0",
"react-native-render-html": "^4.1.2",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.0.0-beta.10",
"react-native-snap-carousel": "^3.8.4",
"react-native-splash-screen": "^3.2.0",
"react-native-status-bar-height": "^2.4.0",
"react-native-svg": "^11.0.1",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "^5.10.0",
"react-native-webview-invoke": "^0.5.0",
"react-native-yt-player": "^1.0.6",
"react-navigation": "^4.1.1",
"react-navigation-stack": "^2.1.1",
"react-navigation-tabs": "^2.7.0"
},
"devDependencies": {
"@babel/core": "7.8.4",
"@babel/runtime": "7.8.4",
"babel-jest": "25.1.0",
"jest": "25.1.0",
"metro-react-native-babel-preset": "0.58.0",
"react-test-renderer": "16.8.3"
},

Video don't show

Hi, thanks for your good component for React native
Could you do me a favor?
Video don't display. it is only loading spinner.

image

Hope your kind contact.
Thanks

Some videos are taking forever to load in iOS

First of all, thanks a lot for this amazing library to provide a utility to play the youtube videos.

I am using this youtube player for an iOS application. Most of the youtube videos are being played successfully by the player, but some of the videos take forever to load in some of the iOS devices.
For example, I am trying to play this youtube video, but it takes forever to load the video. The player get stuck with a loading indicator.

My code for the player is:

<YoutubePlayer
     loop
     videoId="moZOrq0qL3Q"
     autoPlay
     onStart={() => console.log('Video started')}
     onEnd={() => alert('Video Ended')}
     onError={() => {
          console.log('error loading video');
     }}
 />

Testing Environment:

react-native: "0.62.2"
react-native-youtube-player: "1.0.6"
iOS device: iPhone 6
iOS version: "12.4.8"

Can anyone please help me in this or suggest any workaround/solution for this?

Slider thumbImage Issue

Error while updating property 'thumbImage' of a view managed by: RNCSlider

value for thumbImage cannot be cast from double to readablenativemap.

Testing on Real Device and Emulator. results are same. if you need screenshots.

Could not find a declaration file for module react-native-yt-player

Hi,

I am getting an error message saying that the npm is found, however the package itself specifies a main module field that could not be resolved. I gone through the node_modules and I realize that this npm is using typescript and my application runs on .js so I am not sure if that could be the reason why I am getting this error message. Please let me know if this npm does support with javascript. Thank you!

Looks like this is not updated for reanimated v2

Looks like this is not updated for reanimated v2 which is being used already in my project so cant downgrade.
Error:

interpolate is not a function. (in interpolate(width, {
......

in v2 the name has been changed to interpolateNode for whatever reason

Quality change

Hi, thanks for the package. Does this support the option to change the quality of the video?

Video unavailable

Hi there, thanks for the wonderful alternative for youtube player but I am getting this error on most of the videos.
"This video contains from ###### films, which has blocked it from the display on this web or application" getting this error

j

Play pause not working with the latest npx react-native init
Not able to apply for full screen also

Could this support providing start/end times on videos?

I'm looking at implementing this, as I've had the issue with react-native-youtube freezing due to overlay problem with react-native-navigation. Hoping this solution might solve it.

In regards to this API, would it support providing a start/end time for the video, as youtube URL's support this?

Does not seems to work with Expo Cli

Hi, it seems really helpful, thanks for the person who has shared it, but I was wondering if it does work with expo Cli, I do not know how to do the linking part with expo Cli?

Live streaming

im trying to use the player with a live video from youtube and it crashes 2 seconds before it plays.. there is any way to use the player with live video?
thank you

Great Tutorial

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.

Unbelievably un-responsive controls on android

Hello,

Is it just me or are the player controls on android extremely slow to respond?

I've installed all modules correctly and linked them successfully( including react-native-orientation )

Is there an additional step that isn't written on the docs I missed?

Thanks

Slider issue

Slider Seek not working with React native version 0.60.0

requireNativeComponent: "RNCWebView" was not found in the UIManager - android

I'm getting this error when I start the app on Android (I'm using Yarn as package manager):
image

I did not link anything, since I'm using RN 0.62.

package.json:

{
  "name": "mobile",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "npx react-native run-android",
    "ios": "npx react-native run-ios",
    "test": "jest",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.7",
    "@react-navigation/bottom-tabs": "^5.2.5",
    "@react-navigation/native": "^5.1.3",
    "@react-navigation/stack": "^5.2.6",
    "axios": "^0.19.2",
    "react": "16.9.0",
    "react-native": "0.62",
    "react-native-elements": "^1.2.7",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-keyboard-aware-scroll-view": "^0.9.1",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-orientation": "^3.1.3",
    "react-native-reanimated": "^1.7.1",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.4.0",
    "react-native-vector-icons": "^6.6.0",
    "react-native-webview-invoke": "^0.5.1",
    "react-native-yt-player": "^1.0.6",
    "react-redux": "^7.2.0",
    "redux": "^4.0.5",
    "redux-axios-middleware": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "symbol-observable": "^1.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "@types/hoist-non-react-statics": "^3.3.1",
    "@types/jest": "^24.0.24",
    "@types/react-native": "^0.60.25",
    "@types/react-redux": "^7.1.7",
    "@types/react-test-renderer": "16.9.1",
    "@typescript-eslint/eslint-plugin": "^2.12.0",
    "@typescript-eslint/parser": "^2.12.0",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.9.0",
    "redux-devtools-extension": "^2.13.8",
    "redux-logger": "^3.0.6",
    "typescript": "^3.7.3"
  },
  "workspaces": {
    "nohoist": [
      "react",
      "react/**",
      "react-native",
      "react-native/**",
      "@babel",
      "@babel/**",
      "@react-native-community",
      "@react-native-community/**",
      "redux",
      "redux/**",
      "react-redux",
      "react-redux/**",
      "symbol-observable",
      "react-native-linear-gradient",
      "react-native-gesture-handler",
      "@react-navigation",
      "@react-navigation/**",
      "redux-thunk",
      "axios",
      "react-native-keyboard-aware-scroll-view",
      "redux-logger",
      "react-native-elements",
      "react-native-elements/**",
      "react-native-vector-icons",
      "react-native-vector-icons/**",
      "react-native-reanimated",
      "react-native-reanimated/**",
      "react-native-webview",
      "react-native-webview/**",
      "react-native-webview-invoke",
      "react-native-webview-invoke/**",
      "react-native-orientation",
      "react-native-orientation/**"
    ]
  },
  "jest": {
    "preset": "react-native",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.