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<Props, State> {
    constructor(props: Props | Readonly<Props>) {
        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<State> = {
        paused: true
    }
    public paused = true
    public playerRef = null
    public videoAddlistener = null
    public unActiveVideoAddlistener = null


    render() {
        // console.log(this.paused)
        let { paused } = this.state;

        return (
            <>
            </>
            // <View>
            //     {
            //         paused ? <Text style={{ color: '#fff' }}>无需播放</Text> :
            //             <Text style={{ color: '#fff' }}>播放中</Text>

            //     }
            // <VideoPlayer />
            // < Video
            //     source={{ uri: "http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4" }}
            //     // <Video source={require("../../assets/test.mp4")}//在给定的扩展版本中查找.mp4文件（background.mp4）.
            //     ref={c => { this.playerRef = c }}
            //     rate={1}                   //0暂停,1是正常的.
            //     volume={1.0}                 //0静音,1是正常的.
            //     muted={false}                //完全静音.
            //     paused={paused}               //完全暂停播放.
            //     resizeMode="cover"           //以纵横比填充整个屏幕.
            //     repeat={false}                //永远重复.
            //     // onLoad={this.onLoad}
            //     // onProgress={this.onProgress}
            //     // onLoadStart={this.onLoadStart}//视频开始加载时的回调
            //     // onLoad={this.setDuration}    //视频加载时的回调
            //     // onProgress={this.时刻设定}    //回调每250毫秒〜与currentTime的
            //     // onEnd={this.onEnd}           //播放完成时的回调
            //     // onError={this.videoError}    //视频无法加载时回调
            //     style={styles.backgroundVideo}

            // />
            // </View>
        );

    }
}
const styles = StyleSheet.create({
    main: {

    },
    backgroundVideo: {
        width: width - px2dp(25),
        height: px2dp(200),
        backgroundColor: "#000",

    },
})