import React, { Component } from 'react' import { StyleSheet, View, Text, Image, DeviceEventEmitter } from 'react-native' import Video from 'react-native-video'; import VideoPlayer from '.'; import { px2dp, width } from '../../utils/base'; export interface Props { activeIndex: number index: any isTop: boolean } export interface State { paused: boolean } export default class VideoTest extends React.Component { constructor(props: Props | Readonly) { super(props); } componentDidMount() { // this.props.navigation.addListener( // 'focus', () => { let { paused } = this.state; this.unActiveVideoAddlistener = DeviceEventEmitter.addListener("unActiveVideo", (e) => { console.log("结果二") paused = true this.setState({ paused }) // this.playerRef.setNativeProps({ // paused: paused // }) }) this.videoAddlistener = DeviceEventEmitter.addListener("activeVideo", (e) => { console.log("打印结果1", e.activeIndex) if (this.props.index == e.activeIndex) { paused = false } else { paused = true } this.setState({ paused }) // this.playerRef.setNativeProps({ // paused: paused // }) }) // this.playerRef.setNativeProps({ // paused: paused // }) // console.log("到这里了,", this.props.index, this.activeIndex) // if (this.props.index == this.props.activeIndex) { // this.paused = false // console.log("有一个") // } else { this.paused = true } // }) } componentWillUnmount() { this.videoAddlistener && this.videoAddlistener.remove() this.unActiveVideoAddlistener && this.unActiveVideoAddlistener.remove() } public readonly state: Readonly = { paused: true } public paused = true public playerRef = null public videoAddlistener = null public unActiveVideoAddlistener = null render() { // console.log(this.paused) let { paused } = this.state; return ( <> // // { // paused ? 无需播放 : // 播放中 // } // // < Video // source={{ uri: "http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4" }} // // ); } } const styles = StyleSheet.create({ main: { }, backgroundVideo: { width: width - px2dp(25), height: px2dp(200), backgroundColor: "#000", }, })