2.2.0 • Published 6 months ago

react-native-media-console v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

🕹 react-native-media-console

platforms GitHub issues GitHub GitHub top language Maintenance npm

VideoPlayer for the React Native <Video/> component at react-native-video.

demogif

⚠️ Note:

We're only supporting the beta version of react-native-video. Since it looks stable enough except for the subtitles (which might still be a WIP at the time of writing), we're already using it in production at http://englishdiscoveries.net/

⭐️ Features

This package contains a simple set of GUI controls that work with the react-native-video <Video> component.

  • react-native-reanimated
  • Back Button
  • Volume bar
  • Fullscreen button
  • Play/Pause button
  • Rewind/Forward buttons
  • Seekbar
  • Title
  • Error handling
  • Timer
  • Rate button

By default the <VideoPlayer> accepts a navigator property from React's built-in <Navigator> which pops the current scene off the stack when tapped. Alternatively you can provide your own onBack prop to the component to override this functionality. You should also provide your own onEnd prop to the component so it knows what to do when a video ends playback.

By default, tapping the screen anywhere will show the player controls. After 15s the controls disappear. Double tapping will toggle fullscreen.

⚙️ Installation

Run yarn add react-native-video react-native-media-console

Then follow installation instructions from react-native-video.

If you are using react-native-reanimated, then you can use yard add @react-native-media-console/reanimated

🛠 Usage

The <VideoPlayer> component follows the API of the <Video> component at react-native-video. It also takes a number of additional props which are outlined in the API section.

For basic operation the <VideoPlayer> component requires a video source and a navigator property. The default back button functionality in the component relies on using the built-in <Navigator> functionality in React Native and pops the current scene off the stack. This can be overridden if desired, see the API for more details.

// At the top where our imports are...
import VideoPlayer from 'react-native-media-console';
// 👇 if you use react-native-reanimated 
import {useAnimations} from '@react-native-media-console/reanimated';

// in the component's render() function
<VideoPlayer
    useAnimations={useAnimations}
    source={{uri: 'https://vjs.zencdn.net/v/oceans.mp4'}}
    navigator={props.navigator}
/>;

To play a local file, use require syntax like so:

<VideoPlayer source={require('path/to/file')}/>

🧰 API

The <VideoPlayer> component can take a number of inputs to customize it as needed. They are outlined below:

Props

You can pass any of the props that the <Video /> component at react-native-video takes. Simply add them onto the <VideoPlayer /> and it will pass them through to the <Video /> component.

In addition, the <VideoPlayer /> also takes these props:

PropTypeDefaultDescription
alwaysShowControlsBooleanfalseAlways show controls.
controlAnimationTimingInteger500The amount of time (in milliseconds) to animate the controls in and out.
controlTimeoutDelayInteger15000Hide controls after X amount of time in milliseconds
doubleTapTimeInteger130Tapping twice within this amount of time in milliseconds is considered a double tap. Single taps will not be actioned until this time has expired.
isFullscreenBooleanfalseThe VideoPlayer fullscreen state
navigatorNavigatornullWhen using the default React Native navigator and do not override the onBack function, you'll need to pass the navigator to the VideoPlayer for it to function
rewindTimeInteger15Number of seconds to rewind or forward.
seekColorString(#HEX)'#FFF'Fill/handle colour of the seekbar
showDurationBooleanfalseShow duration of the media.
showOnStartBooleanfalseShow or hide the controls on first render
showOnEndBooleanfalseShow or hide the controls on end of video
showTimeRemainingBooleanfalseIf true, show the time remaing, else show the current time in the Player.
showHoursBooleanfalseIf true, convert time to hours in the Player
tapAnywhereToPauseBooleanfalseIf true, single tapping anywhere on the video (other than a control) toggles between playing and paused.
toggleResizeModeOnFullscreenBooleanfalseIf true, clicking the fullscreen button will toggle the <Video /> component between cover/contain, set to false if you want to customize fullscreen behaviour
containerStyleViewStyleStyleSheet passed to the container of the component
videoStyleViewStyleStyleSheet passed to the component
videoRefVideoundefinedPass ref to the <Video/> component
pan{ horizontal: Boolean, inverted: Boolean }{ horizontal: true, inverted: false }An object allowing fine grained control over the PanResponder controlling the volume and seek. Use this if you need to apply rotation transformations to the player.

Events

These are various events that you can hook into and fire functions on in the component:

CallbackDescription
onEnterFullscreenFired when the video enters fullscreen after the fullscreen button is pressed
onExitFullscreenFired when the video exits fullscreen after the fullscreen button is pressed
onHideControlsFired when the controls disappear
onShowControlsFired when the controls appear
onErrorFired when an error is encountered when loading the video
onPauseFired when the video is paused after the play/pause button is pressed
onPlayFired when the video begins playing after the play/pause button is pressed
onBackFunction fired when back button is pressed, override if using custom navigation
onEndFired when the video is complete

Controls

These are the various controls that you can turn on/off as needed. All of these props default to false, override them to disable any controls

ControlDescription
disableFullscreenHide the fullscreen button
disablePlayPauseHide the play/pause toggle and the rewind/forward buttons
disableSeekButtonsHide the rewind/forward buttons (but not play/pause)
disableSeekbarHide the seekbar
disableVolumeHide the Volume control
disableTimerHide the timer
disableBackHide the back button
disableOverlayHide the transparent overlay which is active when the controls are shown. Generally used when you want to disable all the controls.

🪲 Debugging

Android:

📃 License

📃 This project is released under the MIT License. \ 💻 By contributing, you agree that your contributions will be licensed under its MIT License.

🏆 Sponsors

jetbrains100englishdislogo100
2.2.0

6 months ago

2.2.0-0

6 months ago

2.1.0-0

8 months ago

2.1.0

8 months ago

2.0.7

10 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.6

1 year ago

2.0.2-0

1 year ago

2.0.0-4

2 years ago

2.0.0-3

2 years ago

2.0.0-2

2 years ago

2.0.0-1

2 years ago

2.0.0-0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.9

2 years ago

1.2.9-0

2 years ago

1.2.8

2 years ago

1.2.8-1

2 years ago

1.2.8-0

2 years ago

1.2.8-3

2 years ago

1.2.8-2

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago