@12stonechurch/react-native-video-controls 中文文档教程
react-native-video-controls
react-native-video< 中 React Native 组件的控件/a>。 要支持 RN 0.45 或更低版本,请使用 1.3.1 或更低版本。
Features
这个包包含一组简单的 GUI 控件,可与 react-native-video 组件。 这包括后退按钮、音量条、全屏切换、播放/暂停切换、搜索栏、标题、错误处理和定时器切换,点击时可以在剩余时间和当前时间之间切换。
默认情况下
接受一个 navigator 属性,它在点击时将当前场景从堆栈中弹出。 或者,您可以向组件提供自己的 onBack 道具以覆盖此功能。 您还应该为组件提供自己的 onEnd 道具,以便它知道在视频播放结束时该怎么做。
默认情况下,点击屏幕的任何地方都会显示播放器控件。 10 秒后控件消失。 双击将切换全屏。
Installation
运行 npm install --save react-native-video react-native-video-controls
然后运行 react-native link react-native-video
如果你使用的是 RN < ; 39 运行 npm install --save react-native-video-controls@1.0.1
。 请注意,此版本包含 react-native-video
作为普通依赖项而不是对等依赖项。
Usage
组件遵循 组件的 API,位于 react-native-video。 它还需要一些额外的道具,这些道具在 API 部分中有概述。
对于基本操作,
组件需要一个视频源和一个导航器属性。 组件中的默认后退按钮功能依赖于使用 React Native 中的内置
功能,并将当前场景从堆栈中弹出。 如果需要,可以覆盖它,请参阅 API 了解更多详细信息。
// At the top where our imports are...
import VideoPlayer from 'react-native-video-controls';
// in the component's render() function
<VideoPlayer
source={{ uri: 'https://vjs.zencdn.net/v/oceans.mp4' }}
navigator={ this.props.navigator }
/>
要播放本地文件,请使用 require 语法,如下所示:
<VideoPlayer source={ require('path/to/file') } />
API
组件可以接受大量输入以根据需要对其进行自定义。 它们概述如下:
Props
您可以传递 组件在 react-native-video 需要。 只需将它们添加到
上,它就会将它们传递给 组件。
此外,
还采用这些道具:
Prop | Type | Default | Description |
---|---|---|---|
toggleResizeModeOnFullscreen | Boolean | true | If true, clicking the fullscreen button will toggle the <Video /> component between cover/contain, set to false if you want to customize fullscreen behaviour |
controlTimeout | Integer | 15000 | Hide controls after X amount of time in milliseconds |
showOnStart | Boolean | true | Show or hide the controls on first render |
videoStyle | StyleSheet | null | React Native StyleSheet object that is appended to the <Video> component |
navigator | Navigator | null | When 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 |
seekColor | String(#HEX) | '#FFF' | Fill/handle colour of the seekbar |
style | StyleSheet | null | React Native StyleSheet object that is appended to the video's parent <View> |
Events
这些是您可以挂钩并在组件中触发功能的各种事件:
Callback | Description |
---|---|
onEnterFullscreen | Fired when the video enters fullscreen after the fullscreen button is pressed |
onExitFullscreen | Fired when the video exits fullscreen after the fullscreen button is pressed |
onError | Fired when an error is encountered when loading the video |
onPause | Fired when the video is paused after the play/pause button is pressed |
onPlay | Fired when the video begins playing after the play/pause button is pressed |
onBack | Function fired when back button is pressed, override if using custom navigation |
onEnd | Fired when the video is complete |
Controls
这些是您可以打开的各种控件/根据需要关闭。 所有这些道具默认为 false,覆盖它们以禁用任何控件
Control | Description |
---|---|
disableFullscreen | Hide the fullscreen button |
disablePlayPause | Hide the play/pause toggle |
disableSeekbar | Hide the seekbar |
disableVolume | Hide the Volume control |
disableTimer | Hide the timer |
disableBack | Hide the back button |
react-native-video-controls
Controls for the React Native <Video>
component at react-native-video. For support with RN 0.45 or lower use version 1.3.1 or lower.
Features
This package contains a simple set of GUI controls that work with the react-native-video <Video>
component. This includes a back button, volume bar, fullscreen toggle, play/pause toggle, seekbar, title, error handling and timer toggle that can switch between time remaining and current time when tapped.
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 10s the controls disappear. Double tapping will toggle fullscreen.
Installation
Run npm install --save react-native-video react-native-video-controls
Then run react-native link react-native-video
If you're using RN < 39 run npm install --save react-native-video-controls@1.0.1
. Note this version includes react-native-video
as a normal dependency instead of a peer-dependency.
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-video-controls';
// in the component's render() function
<VideoPlayer
source={{ uri: 'https://vjs.zencdn.net/v/oceans.mp4' }}
navigator={ this.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:
Prop | Type | Default | Description |
---|---|---|---|
toggleResizeModeOnFullscreen | Boolean | true | If true, clicking the fullscreen button will toggle the <Video /> component between cover/contain, set to false if you want to customize fullscreen behaviour |
controlTimeout | Integer | 15000 | Hide controls after X amount of time in milliseconds |
showOnStart | Boolean | true | Show or hide the controls on first render |
videoStyle | StyleSheet | null | React Native StyleSheet object that is appended to the <Video> component |
navigator | Navigator | null | When 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 |
seekColor | String(#HEX) | '#FFF' | Fill/handle colour of the seekbar |
style | StyleSheet | null | React Native StyleSheet object that is appended to the video's parent <View> |
Events
These are various events that you can hook into and fire functions on in the component:
Callback | Description |
---|---|
onEnterFullscreen | Fired when the video enters fullscreen after the fullscreen button is pressed |
onExitFullscreen | Fired when the video exits fullscreen after the fullscreen button is pressed |
onError | Fired when an error is encountered when loading the video |
onPause | Fired when the video is paused after the play/pause button is pressed |
onPlay | Fired when the video begins playing after the play/pause button is pressed |
onBack | Function fired when back button is pressed, override if using custom navigation |
onEnd | Fired 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
Control | Description |
---|---|
disableFullscreen | Hide the fullscreen button |
disablePlayPause | Hide the play/pause toggle |
disableSeekbar | Hide the seekbar |
disableVolume | Hide the Volume control |
disableTimer | Hide the timer |
disableBack | Hide the back button |