国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Android WebView H5視頻播放實(shí)現(xiàn)全屏播放功能、全屏按鈕不顯示、灰顯、點(diǎn)擊無(wú)效問(wèn)題解決方案

這篇具有很好參考價(jià)值的文章主要介紹了Android WebView H5視頻播放實(shí)現(xiàn)全屏播放功能、全屏按鈕不顯示、灰顯、點(diǎn)擊無(wú)效問(wèn)題解決方案。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

一、官方介紹

HTML5 video support
HTML5 Video support In order to support inline HTML5 video in your application, 
you need to have hardware acceleration turned on, and set a WebChromeClient. 
For full screen support, implementations of onShowCustomView(View, WebChromeClient.CustomViewCallback) 
and onHideCustomView() are required, getVideoLoadingProgressView() is optional.
  1. 打開(kāi)硬件加速(3.0以上版本支持)
  2. set一個(gè)WebChromClient,實(shí)現(xiàn)onShowCustomView() 方法和onHideCustomView()方法
  3. 全屏支持

二、實(shí)現(xiàn)解決

  1. 打開(kāi)硬件加速
  • 在Manifest中,對(duì)應(yīng)的Activity添加: android:hardwareAccelerated = “true”。
  • 防止h5重新加載:Manifest中,對(duì)應(yīng)的Activity添加: android:configChanges=“keyboardHidden|orientation|screenSize”
  • 切換橫屏?xí)r,屏幕的H5內(nèi)容始終以豎屏顯示:Manifest中,對(duì)應(yīng)的Activity添加: android:screenOrientation=“portrait”
<activity
    android:name=".uicomponent.WebViewActivity"
    android:configChanges="orientation|screenSize|keyboardHidden" //防止h5重新加載
    android:hardwareAccelerated="true" //硬件加速
    android:screenOrientation="portrait" //當(dāng)我們切換橫豎屏的時(shí)候,屏幕的內(nèi)容始終以豎屏顯示,而不會(huì)根據(jù)屏幕的方向來(lái)顯示內(nèi)容
    android:theme="@style/AppTheme.NoActionBar" />
  1. WebView中設(shè)置WebChromClient實(shí)現(xiàn)接口onShowCustomView() 方法和onHideCustomView()方法, 實(shí)現(xiàn)后即顯示全屏播放按鈕,但是點(diǎn)擊無(wú)反應(yīng),需要實(shí)現(xiàn)全屏支持。

  2. 全屏支持實(shí)現(xiàn):WebView在點(diǎn)擊全屏按鈕后調(diào)用onShowCustomView方法,而全屏的視頻會(huì)在其參數(shù)view中進(jìn)行渲染。我們需要在Activity中寫(xiě)一個(gè)viewRoot,在onShowCustomView觸發(fā)后,將其view傳入viewRoot,且使APP橫屏,達(dá)到全屏顯示。

@SuppressLint("StaticFieldLeak")
private var mCustomView: View? = null //全屏渲染視頻的View
private var webRoot: FrameLayout? = null// 顯示全屏視頻的布局
private var mCustomViewCallback: CustomViewCallback? = null

@SuppressLint("SourceLockedOrientationActivity")
override fun onShowCustomView(view: View?, callback: CustomViewCallback?) {
    super.onShowCustomView(view, callback)
    try {
        if (mCustomView != null) { //當(dāng)上一個(gè)view存在時(shí),隱藏全屏
            callback?.onCustomViewHidden()
            return
        }
        mCustomView = view
        webRoot?.addView(mCustomView)
        mCustomViewCallback = callback
        webView?.visibility = View.GONE
        val actionBar = supportActionBar
        actionBar?.hide()
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

@SuppressLint("SourceLockedOrientationActivity")
override fun onHideCustomView() {
    try {
        webView?.visibility = View.VISIBLE
        val actionBar = supportActionBar
        actionBar?.show()
        if (mCustomView == null) { //當(dāng)上一個(gè)view不存在時(shí),不處理
            return
        }
        mCustomView?.visibility = View.GONE
        webRoot?.removeView(mCustomView)
        mCustomViewCallback?.onCustomViewHidden()
        mCustomView = null
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
    } catch (e: Exception) {
        e.printStackTrace()
    }
    super.onHideCustomView()
} 

override fun onProgressChanged(view: WebView?, newProgress: Int) {
    super.onProgressChanged(view, newProgress)
    progressBar?.progress = newProgress
}

xml

<FrameLayout
    android:id="@+id/web_root"
    app:layout_constraintBottom_toTopOf="@id/v_bottom"
    app:layout_constraintTop_toBottomOf="@id/v_top"
    android:layout_width="match_parent"
    android:layout_height="0dp">

   <WebView
         android:id="@+id/webview"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
   
    <ProgressBar
        android:id="@+id/progress_bar"
        style="?android:progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="1.5dp"
        android:max="100"
        android:progressDrawable="@drawable/webview_progress_bar_style" />
</FrameLayout>

三、寫(xiě)在最后

此文章為個(gè)人開(kāi)發(fā)時(shí)記錄,有時(shí)時(shí)間有限,無(wú)法深入研究,若看到此文章后有其他見(jiàn)解或解決方式,歡迎留言交流??????

————————————————
版權(quán)聲明:轉(zhuǎn)載請(qǐng)附上原文出處鏈接及本聲明。
原文鏈接:
https://blog.csdn.net/weixin_44158429/article/details/130217214文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-493111.html

到了這里,關(guān)于Android WebView H5視頻播放實(shí)現(xiàn)全屏播放功能、全屏按鈕不顯示、灰顯、點(diǎn)擊無(wú)效問(wèn)題解決方案的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包