Video
Video是实现HTMLVideoElement接口的React Native组件,该接口可扩展HTMLMediaElement接口。
扩展
Media<VideoProps,VideoState>
实现
属性
context
context:
unknown
如果使用新的样式上下文,请在类中重新声明,使其成为静态contextType的React.ContextType。应与类型注释或静态contextType一起使用。
示例
static contextType = MyContext
// 对于3.7之前的TS:
context!: React.ContextType<typeof MyContext>
// 对于TS 3.7及更高版本:
declare context: React.ContextType<typeof MyContext>
参见
继承自
Media.context
props
readonlyprops:Readonly<VideoProps&MediaProps&ViewProps>
继承自
Media.props
refs
refs:
object
索引签名
[key: string]: ReactInstance
已弃用
参见
继承自
Media.refs
state
state:
Readonly<VideoState&MediaState>
继承自
Media.state
contextType?
staticoptionalcontextType:Context<any>
如果设置,this.context将在运行时设置为给定上下文的当前值。
示例
type MyContext = number
const Ctx = React.createContext<MyContext>(0)
class Foo extends React.Component {
static contextType = Ctx
context!: React.ContextType<typeof Ctx>
render () {
return <>My context's value: {this.context}</>;
}
}
参见
https://react.dev/reference/react/Component#static-contexttype
继承自
Media.contextType
方法
componentDidCatch()?
optionalcomponentDidCatch(error,errorInfo):void
捕获后代组件中生成的异常。未处理的异常将导致整个组件树被卸载。
参数
error
Error
errorInfo
ErrorInfo
返回值
void
继承自
Media.componentDidCatch
componentWillMount()?
optionalcomponentWillMount():void
在执行安装操作及和调用Component.render之前立即调用。避免在此方法中引入任何副作用或订阅。
注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。
返回值
void
已弃用
16.3,改用ComponentLifecycle.componentDidMount componentDidMount或构造函数;在React 17中将不再适用
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
Media.componentWillMount
componentWillReceiveProps()?
optionalcomponentWillReceiveProps(nextProps,nextContext):void
当组件可能收到新属性时调用。即使属性并未更改,React也可能会调用此方法。因此,如果您只想处理更改,那么一定要对新的属性和现有的属性进行比较。
调用Component.setState通常不会触发此方法。
注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。
参数
nextProps
Readonly<VideoProps & MediaProps & ViewProps>
nextContext
any
返回值
void
已弃用
16.3,改用静态StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps;在React 17中将不再适用
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
Media.componentWillReceiveProps
componentWillUpdate()?
optionalcomponentWillUpdate(nextProps,nextState,nextContext):void
如果收到新属性或状态,则在进行渲染之前立即调用。在初始渲染时不会调用。
注意: 您不能在此处调用Component.setState。
注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。
参数
nextProps
Readonly<VideoProps & MediaProps & ViewProps>
nextState
Readonly<VideoState & MediaState>
nextContext
any
返回值
void
已弃用
16.3,改用getSnapshotBeforeUpdate;在React 17中将不再适用
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
Media.componentWillUpdate
destroyMediaPlayerSync()
destroyMediaPlayerSync(
timeoutInMs):MediaPlayerDeInitStatus
参数
timeoutInMs
number
客户端设置的超时时间阈值
返回值
MediaPlayerDeInitStatus
MediaPlayerDeInitStatus
简述
同步取消播放器初始化
覆盖
Media.destroyMediaPlayerSync
forceUpdate()
forceUpdate(
callback?):void
参数
callback?
() => void
返回值
void
继承自
Media.forceUpdate
getSnapshotBeforeUpdate()?
optionalgetSnapshotBeforeUpdate(prevProps,prevState):any
在React将Component.render渲染结果应用于文档并返回要提供给componentDidUpdate的对象之前运行。对于在Component.render渲染导致发生更改之前保存滚动位置等内容很有用。
注意:此方法的存在会阻止任何已弃用的生命周期事件运行。
参数
prevProps
Readonly<VideoProps & MediaProps & ViewProps>
prevState
Readonly<VideoState & MediaState>
返回值
any
继承自
Media.getSnapshotBeforeUpdate
setState()
setState<
K>(state,callback?):void
类型参数
• K extends never
参数
state
VideoState & MediaState |
(prevState, props) => VideoState & MediaState | Pick<VideoState & MediaState, K> |
Pick<VideoState & MediaState, K> |
callback?
() => void
返回值
void
继承自
Media.setState
shouldComponentUpdate()?
optionalshouldComponentUpdate(nextProps,nextState,nextContext):boolean
调用以确定属性和状态更改是否应触发重新渲染。
Component always returns true.PureComponent可对属性和状态进行浅层比较,并在发现任何属性或状态更改时返回true。
如果返回false,则不会调用Component.render、componentWillUpdate和componentDidUpdate。
参数
nextProps
Readonly<VideoProps & MediaProps & ViewProps>
nextState
Readonly<VideoState & MediaState>
nextContext
any
返回值
boolean
继承自
Media.shouldComponentUpdate
UNSAFE_componentWillMount()?
optionalUNSAFE_componentWillMount():void
在执行安装操作及和调用Component.render之前立即调用。避免在此方法中引入任何副作用或订阅。
此方法在React 17中仍然有效。
注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。
返回值
void
已弃用
16.3,改用ComponentLifecycle.componentDidMount componentDidMount或构造函数
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
Media.UNSAFE_componentWillMount
UNSAFE_componentWillReceiveProps()?
optionalUNSAFE_componentWillReceiveProps(nextProps,nextContext):void
当组件可能收到新属性时调用。即使属性并未更改,React也可能会调用此方法。因此,如果您只想处理更改,那么一定要对新的属性和现有的属性进行比较。
调用Component.setState通常不会触发此方法。
此方法在React 17中仍然有效。
注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。
参数
nextProps
Readonly<VideoProps & MediaProps & ViewProps>
nextContext
any
返回值
void
已弃用
16.3,改用静态StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
Media.UNSAFE_componentWillReceiveProps
UNSAFE_componentWillUpdate()?
optionalUNSAFE_componentWillUpdate(nextProps,nextState,nextContext):void
如果收到新属性或状态,则在进行渲染之前立即调用。在初始渲染时不会调用。
注意: 您不能在此处调用Component.setState。
此方法在React 17中仍然有效。
注意:如果存在NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate或StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps,则会阻止此方法被调用。
参数
nextProps
Readonly<VideoProps & MediaProps & ViewProps>
nextState
Readonly<VideoState & MediaState>
nextContext
any
返回值
void
已弃用
16.3,改用getSnapshotBeforeUpdate
参见
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update
- https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
继承自
Media.UNSAFE_componentWillUpdate
Last updated: 2025年10月2日

