Monday, 6 January 2020

Android fullscreen youtube video in WebView + Kotlin






Kotlin+ FullScreen Youtube in Webview



inner class MyWebClient : WebChromeClient() {
    private var mCustomView: View? = null
    private var mCustomViewCallback: 
            WebChromeClient.CustomViewCallback? = null
    protected var mFullscreenContainer: FrameLayout? = null
    private var mOriginalOrientation: Int = 0
    private var mOriginalSystemUiVisibility: Int = 0

    override fun getDefaultVideoPoster(): Bitmap? {
        return if (this == null) {
            null
        } else BitmapFactory.decodeResource(resources, 2130837573)
    }

    override fun onHideCustomView() {
        (window.decorView as FrameLayout).removeView(this.mCustomView)
        this.mCustomView = null
        window.decorView.systemUiVisibility = this.mOriginalSystemUiVisibility
        requestedOrientation = this.mOriginalOrientation
        this.mCustomViewCallback!!.onCustomViewHidden()
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        this.mCustomViewCallback = null
    }

    override fun onShowCustomView(paramView: View, paramCustomViewCallback: 
                                 WebChromeClient.CustomViewCallback) {
        if (this.mCustomView != null) {
            onHideCustomView()
            return
        }
        this.mCustomView = paramView
        this.mOriginalSystemUiVisibility = window.decorView.systemUiVisibility
        this.mOriginalOrientation = requestedOrientation
        this.mCustomViewCallback = paramCustomViewCallback
        (window.decorView as FrameLayout).addView(this.mCustomView,
                    FrameLayout.LayoutParams(-1, -1))
        window.decorView.systemUiVisibility = 3846
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    }

No comments:

Post a Comment