1.0.0 • Published 4 years ago

@mores8/rn-video-player v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

rn-video-player

React Native video player & controls UI

Demo

Installation

  1. Install the required packages in your React Native project:

    npm install react-native-video react-native-linear-gradient react-native-orientation-locker react-native-safe-area-context react-native-vector-icons @react-native-community/slider @sayem314/react-native-keep-awake 

    From React Native 0.60 and higher, linking is automatic. So you don't need to run react-native link.

    For iOS, install pods to complete the linking.

    npx pod-install ios

    Note: react-native-vector-icons requires additional steps for installation.

  2. Install rn-video-player

    npm install @mores8/rn-video-player

Usage

import VideoPlayer from "@mores8/rn-video-player";

<VideoPlayer
    style={{height: ,width: 320}}
    url={sampleUrl}
/>

Check out the example project for more examples.

Props

PropTypeRequiredDefaultDescription
urlstring, numberYesA URL string (or number for local) is required.
autoPlayboolNofalseAutoplays the video as soon as it's loaded
loopboolNofalseAllows the video to continuously loop
titlestringNo''Adds a title of your video at the top of the player
placeholderstringNoundefinedAdds an image placeholder while it's loading and stopped at the beginning
logostringNoundefinedAdds an image logo at the top left corner of the video
themestringNo'white'Adds an optional theme colour to the players controls
hideFullScreenControlboolNofalseThis hides the full screen control
styleView.styleNoundefinedApply styles directly to the Video player (ignored in fullscreen mode)
resizeModestringNo'contain'Fills the whole screen at aspect ratio. contain, cover etc
rotateToFullScreenboolNofalseTapping the fullscreen button will rotate the screen. Also rotating the screen will automatically switch to fullscreen mode
fullScreenOnlyboolNofalseThis will play only in fullscreen mode
inlineOnlyboolNofalseThis hides the fullscreen button and only plays the video in inline mode
playInBackgroundboolNofalseAudio continues to play when app enters background.
playWhenInactiveboolNofalseiOS Video continues to play when control or notification center are shown.
ratenumberNo1Adjusts the speed of the video. 0 = stopped, 1.0 = normal
volumenumberNo1Adjusts the volume of the video. 0 = mute, 1.0 = full volume
onMorePressfunctionNoundefinedAdds an action button at the top right of the player. Use this callback function for your own use. e.g share link
onFullScreenfunctionNo(value) => {}Returns the fullscreen status whenever it toggles. Useful for situations like react navigation.
lockPortraitOnFsExitboolNofalseKeep Portrait mode locked after Exiting from Fullscreen mode
lockRationumberNoundefinedForce a specific ratio to the Video player. e.g. lockRatio={16 / 9}
onLoadfunctionNo(data) => {}Returns data once video is loaded
onProgressfunctionNo(progress) => {}Returns progress data
onEndfunctionNo() => {}Invoked when video finishes playing
onErrorfunctionNo(error) => {}Returns an error message argument
onPlayfunctionNo(playing) => {}Returns a boolean during playback
controlDurationnumberNo3Set the visibility time of the pause button and the progress bar after the video was started

Example

import * as React from 'react';
import { StyleSheet, View, useWindowDimensions } from 'react-native';
import VideoPlayer from "@mores8/rn-video-player";

const sampleUrl = 'url to video content';
function App() {
  const windowWidth = useWindowDimensions().width;
  const windowHeight = useWindowDimensions().height;

  const containerStyle = {
    flex: 1,
    height: windowHeight,
    width: windowWidth,
  };

  return (
    <View style={containerStyle}>
      <VideoPlayer
        autoPlay
        style={{height: '100%',width: '100%'}}
        url={sampleUrl}
        hideFullScreenControl={false}
        rotateToFullScreen={true}
      />
    </View>
  );
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT