package com.shuangyubang.mofun_flutter_plugin_video

import android.content.Context
import android.view.Gravity
import android.view.View
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.LinearLayout
import com.fgodt.mixplayer.Player
import com.fgodt.mixplayer.mixPlayerCallBack

class MofunRealVideoView(val context: Context) : mixPlayerCallBack {

    private var trueView:FrameLayout? = null

    fun getView(): View? {
        synchronized(MofunRealVideoView::class) {
            if (trueView == null){
                initView()
            }
        }
        return trueView
    }

    private fun initView(){
        trueView = FrameLayout(context)
        val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT)
        params.gravity = Gravity.TOP
        params.height = 1080 * 9 / 16
        val mixplayer = Player(context)
        mixplayer.setMixCall(this)
        mixplayer.addMixSource("mix1", 0.0, -1.0)
        mixplayer.addMixSource("silence", 0.0, -1.0)
        // mixplayer.selectAudioSource("silence");
        // mixplayer.selectAudioSource("mix1");

        trueView?.addView(mixplayer, params)

    }

    override fun mix_call(name: String?, data: ByteArray?, len: Int): Int {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun closeMsg(msg: String?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
}