package com.tencent.liteav.demo.superplayer.util

object PlayerUtil {
    @JvmStatic
    val STATE_PLAY = 0

    @JvmStatic
    val STATE_RESUME = 1

    @JvmStatic
    val STATE_PAUSE = 2

    @JvmStatic
    val STATE_STOP = 3

    @JvmStatic
    val STATE_LOADING = 4

    interface Listener {
        fun onStatePlay()

        fun onStateResume()

        fun onStatePause()

        fun onStateStop()

        fun onStateLoading()
    }

    private val listeners: MutableList<Listener> = mutableListOf()

    public fun addListener(listener: Listener) {
        listeners.add(listener)
    }

    public fun removeListener(listener: Listener) {
        listeners.remove(listener)
    }

    public fun sendNewTimer(state: Int) {
        when (state) {
            STATE_PLAY -> for (listener in listeners) {
                listener.onStatePlay()
            }
            STATE_RESUME -> for (listener in listeners) {
                listener.onStateResume()
            }
            STATE_PAUSE -> for (listener in listeners) {
                listener.onStatePause()
            }
            STATE_STOP -> for (listener in listeners) {
                listener.onStateStop()
            }
            STATE_LOADING -> for (listener in listeners) {
                listener.onStateLoading()
            }
            else -> {

            }
        }

    }
}