@12stonechurch/react-native-video-controls 中文文档教程

发布于 3年前 浏览 24 项目主页 更新于 3年前

react-native-video-controls

react-native-video< 中 React Native 组件的控件/a>。 要支持 RN 0.45 或更低版本,请使用 1.3.1 或更低版本。

Features

这个包包含一组简单的 GUI 控件,可与 react-native-video 组件。 这包括后退按钮、音量条、全屏切换、播放/暂停切换、搜索栏、标题、错误处理和定时器切换,点击时可以在剩余时间和当前时间之间切换。

How it looks

默认情况下 < /code> 从 React 的内置 接受一个 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 需要。 只需将它们添加到 上,它就会将它们传递给 组件。

此外, 还采用这些道具:

PropTypeDefaultDescription
toggleResizeModeOnFullscreenBooleantrueIf true, clicking the fullscreen button will toggle the <Video /> component between cover/contain, set to false if you want to customize fullscreen behaviour
controlTimeoutInteger15000Hide controls after X amount of time in milliseconds
showOnStartBooleantrueShow or hide the controls on first render
videoStyleStyleSheetnullReact Native StyleSheet object that is appended to the <Video> component
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
seekColorString(#HEX)'#FFF'Fill/handle colour of the seekbar
styleStyleSheetnullReact Native StyleSheet object that is appended to the video's parent <View>

Events

这些是您可以挂钩并在组件中触发功能的各种事件:

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
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

这些是您可以打开的各种控件/根据需要关闭。 所有这些道具默认为 false,覆盖它们以禁用任何控件

ControlDescription
disableFullscreenHide the fullscreen button
disablePlayPauseHide the play/pause toggle
disableSeekbarHide the seekbar
disableVolumeHide the Volume control
disableTimerHide the timer
disableBackHide 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.

How it looks

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:

PropTypeDefaultDescription
toggleResizeModeOnFullscreenBooleantrueIf true, clicking the fullscreen button will toggle the <Video /> component between cover/contain, set to false if you want to customize fullscreen behaviour
controlTimeoutInteger15000Hide controls after X amount of time in milliseconds
showOnStartBooleantrueShow or hide the controls on first render
videoStyleStyleSheetnullReact Native StyleSheet object that is appended to the <Video> component
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
seekColorString(#HEX)'#FFF'Fill/handle colour of the seekbar
styleStyleSheetnullReact 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:

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
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
disableSeekbarHide the seekbar
disableVolumeHide the Volume control
disableTimerHide the timer
disableBackHide the back button
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文