0.1.16 • Published 1 year ago

react-native-video-basic-controls v0.1.16

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-video-basic-controls

React native video controls. Controls for the react-native-video component for Android and IOS.

Features

  • Full screen support.
  • Change volume and brightness with Swipe/ Slider controls.
  • Seek forword and back button.
  • Slider customisation.
  • Swipe controls left-side brightness & right-side volume.

Installation

npm install react-native-video-basic-controls

For Brightness or Volume controls install react-native-system-setting

npm install react-native-system-setting

link react-native-system-setting

react-native link

Add permission in android/app/src/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="YourPackageName"
    android:versionCode="1"
    android:versionName="1.0">

    <!-- setBrightness() & setScreenMode() & saveBrightness() -->
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />

    ...

</manifest>

Usage

// Require the module
import MediaControls, {
  PLAYER_STATES,
} from 'react-native-video-basic-controls';

const App = () => {
  const [currentTime, setCurrentTime] = useState(0);
  const [duration, setDuration] = useState(0);
  const [isFullScreen, setIsFullScreen] = useState(false);
  const [isLoading, setIsLoading] = useState(true);
  const [paused, setPaused] = useState(false);
  const [playerState, setPlayerState] = useState(PLAYER_STATES.PLAYING);

  return (
    <View style={styles.container}>
      <Video {...videoProps} />
      <MediaControls
        duration={duration}
        isLoading={isLoading}
        mainColor="orange"
        onFullScreen={noop}
        onPaused={onPaused}
        onReplay={onReplay}
        onSeek={onSeek}
        onSeeking={onSeeking}
        playerState={playerState}
        progress={currentTime}
      >
        <MediaControls.Toolbar>// ...</MediaControls.Toolbar>
      </MediaControls>
    </View>
  );
};

Refer to example for implementation of this project

Props

Main Props

PropTypeOptionalDefaultDescription
progressnumberNoCurrent time of the media player
durationnumberNoTotal duration of the media
playerStatenumberNoCould be PLAYING, PAUSED or ENDED (take a look at constants section)
onPausedfunctionNoTriggered when the play/pause button is pressed. It returns the new toggled value (PLAYING or PAUSED)
onSeekfunctionNoTriggered when the user released the slider
onReplayfunctionYesTriggered when the replay button is pressed
onSeekingfunctionYesTriggered when the user is interacting with the slider

Other Props

PropTypeOptionalDefaultDescription
isLoadingbooleanYesfalseWhen is loading (displays loading icon).
fadeOutDelaynumberYes5000Allows to customize the delay between fade in and fade out transition.
onFullScreenfunctionYesCustom fullscreen function, triggered when the fullscreen button is pressed.
showOnStartbooleanYestruecontrols the visibility of the controls during the initial render.
fullScreenIconLcomponentYesFullscreen icon (landscape mode).
fullScreenIconPcomponentYesFullscreen icon (Portrait mode).
bufferValuenumberYesAdd buffer value to Slider.
onSkipForStringYesTo seek forward.
onSkipBackStringYesTo seek back.
showVolumebooleanYesfalseShow Volume controls.
showBrightnessbooleanYesfalseShow Brightness controls.
sliderScalenumberYes10Scale brightness/ volume slider on press.
sliderTypeStringYes'Slider'Select brightness/ volume slider type(Slider/swipe).

Style Props

PropTypeOptionalDefaultDescription
mainColorstringYesrgba(12, 83, 175, 0.9)Change custom color to the media controls
containerStyleStyleSheetYesApply styles to the container
toolbarStyleStyleSheetYesApply styles to <MediaControls.Toolbar>
iconStyleStyleSheetYesApply styles to fullscreen icon
sliderStyleStyleSheetYesApply styles to Slider
bufferColorStringYes#fffChange color of buffer view
VSliderOuterStylesStyleSheetYesApply styles to volume/brightness outer slider.
VSliderInnerStylesStyleSheetYesApply styles to volume/brightness track slider.
sliderStyle={{
  thumbStyle:{
     // ...
   },
   trackStyle:{
     // ...
   },
   containerStyle:{
     // ...
   }
}}

Contributing

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

License

MIT