質問

私はピアとcheapoアプリの中でも"フレーム"が当社のウェブサイト...インターネットはモバイルの WebViewClient.までしてください。

ビデオで行っている HTML5 要素があり、これらの作やダンディChrome、iphone、およびこれは固定のエンコードの問題で当社のスタッフには様々な場面で Android のネイティブブラウザです。

現在の摩擦: WebView ないようにします。ます。できますをクリックし、ポスター画像は、何も起こりません。

Googlingん この あがるように基づいて作成されるべきである'リンク(a href...)ではなく、映像の要素となります。(onDownloadListenerが表示されませんが呼び出される映像の要素が...)

また文字をオーバー onShowCustomView、そうなると呼ばれる映像の要素...なshouldOverrideUrlLoading..

されているのではないかと思いない車に引からxmlのサーバーのウでのアプリ"..えのレイアウトのサーバで制御するコンテンツを少なく人に強制アップデートするアプリです。でんを説得できるWebView対応タグのようなネイティブブラウザでいることができてしまいます。

私は明確に情報を見落とさないよう明白な..がんについてどのようにお考えですか。

役に立ちましたか?

解決

私は、誰かがそれを読むと、結果に興味があるだけの場合には、このトピックに答えます。 WebViewの内のビデオ要素(ビデオHTML5タグ)を表示することが可能であるが、私は数日のためにそれに対処しなければならなかったと言わなければなりません。これらは、これまでフォローする私が持っていた手順は次のとおりです。

-find適切にエンコードされたビデオ

-WhenではJavaScriptセットのWebViewを、初期化、WebViewClientとWebChromeClientをプラグインINSます。

url = new String("http://broken-links.com/tests/video/"); 
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setWebChromeClient(chromeClient);
mWebView.setWebViewClient(wvClient);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.loadUrl(url);

-handle WebChromeClientオブジェクト内onShowCustomView。

@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
    super.onShowCustomView(view, callback);
    if (view instanceof FrameLayout){
        FrameLayout frame = (FrameLayout) view;
        if (frame.getFocusedChild() instanceof VideoView){
            VideoView video = (VideoView) frame.getFocusedChild();
            frame.removeView(video);
            a.setContentView(video);
            video.setOnCompletionListener(this);
            video.setOnErrorListener(this);
            video.start();
        }
    }
}

Web表示に戻って取得するためにonCompletionやビデオのためのonErrorイベントが、-handleます。

public void onCompletion(MediaPlayer mp) {
    Log.d(TAG, "Video completo");
    a.setContentView(R.layout.main);
    WebView wb = (WebView) a.findViewById(R.id.webview);
    a.initWebView();
}

しかし、今、私は重要な問題が残っていると言うべきです。私は一度だけそれを再生することができます。私はビデオディスパッチャ(ポスターやいくつかの再生ボタンのいずれか)をクリックして二回目は、それは何もしません。

私はまた、代わりにメディアプレーヤーのウィンドウを開くのWebViewのフレームの中に遊びにビデオ、たいと思いますが、これは私にとって二次的な問題である。

私はそれが誰かに助けを願って、私はまた、任意のコメントや提案に感謝します。

Saludos、terrícolas。

他のヒント

長い研究の結果、これを機能させることができました。次のコードを参照してください。

テスト.java

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;

public class Test extends Activity {

    HTML5WebView mWebView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mWebView = new HTML5WebView(this);

        if (savedInstanceState != null) {
            mWebView.restoreState(savedInstanceState);
        } else {    
            mWebView.loadUrl("http://192.168.1.18/xxxxxxxxxxxxxxxx/");
        }

        setContentView(mWebView.getLayout());
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mWebView.saveState(outState);
    }

    @Override
    public void onStop() {
        super.onStop();
        mWebView.stopLoading();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mWebView.inCustomView()) {
                mWebView.hideCustomView();
            //  mWebView.goBack();
                //mWebView.goBack();
                return true;
            }

        }
        return super.onKeyDown(keyCode, event);
    }
}

HTML%VIDEO.java

package com.ivz.idemandtest;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;

public class HTML5WebView extends WebView {

    private Context                             mContext;
    private MyWebChromeClient                   mWebChromeClient;
    private View                                mCustomView;
    private FrameLayout                         mCustomViewContainer;
    private WebChromeClient.CustomViewCallback  mCustomViewCallback;

    private FrameLayout                         mContentView;
    private FrameLayout                         mBrowserFrameLayout;
    private FrameLayout                         mLayout;

    static final String LOGTAG = "HTML5WebView";

    private void init(Context context) {
        mContext = context;     
        Activity a = (Activity) mContext;

        mLayout = new FrameLayout(context);

        mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(a).inflate(R.layout.custom_screen, null);
        mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.main_content);
        mCustomViewContainer = (FrameLayout) mBrowserFrameLayout.findViewById(R.id.fullscreen_custom_content);

        mLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);

        // Configure the webview
        WebSettings s = getSettings();
        s.setBuiltInZoomControls(true);
        s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        s.setUseWideViewPort(true);
        s.setLoadWithOverviewMode(true);
      //  s.setSavePassword(true);
        s.setSaveFormData(true);
        s.setJavaScriptEnabled(true);
        mWebChromeClient = new MyWebChromeClient();
        setWebChromeClient(mWebChromeClient);

        setWebViewClient(new WebViewClient());

setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

        // enable navigator.geolocation 
       // s.setGeolocationEnabled(true);
       // s.setGeolocationDatabasePath("/data/data/org.itri.html5webview/databases/");

        // enable Web Storage: localStorage, sessionStorage
        s.setDomStorageEnabled(true);

        mContentView.addView(this);
    }

    public HTML5WebView(Context context) {
        super(context);
        init(context);
    }

    public HTML5WebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public HTML5WebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    public FrameLayout getLayout() {
        return mLayout;
    }

    public boolean inCustomView() {
        return (mCustomView != null);
    }

    public void hideCustomView() {
        mWebChromeClient.onHideCustomView();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if ((mCustomView == null) && canGoBack()){
                goBack();
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    private class MyWebChromeClient extends WebChromeClient {
        private Bitmap      mDefaultVideoPoster;
        private View        mVideoProgressView;

        @Override
        public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
        {
            //Log.i(LOGTAG, "here in on ShowCustomView");
            HTML5WebView.this.setVisibility(View.GONE);

            // if a view already exists then immediately terminate the new one
            if (mCustomView != null) {
                callback.onCustomViewHidden();
                return;
            }

            mCustomViewContainer.addView(view);
            mCustomView = view;
            mCustomViewCallback = callback;
            mCustomViewContainer.setVisibility(View.VISIBLE);
        }

        @Override
        public void onHideCustomView() {
            System.out.println("customview hideeeeeeeeeeeeeeeeeeeeeeeeeee");
            if (mCustomView == null)
                return;        

            // Hide the custom view.
            mCustomView.setVisibility(View.GONE);

            // Remove the custom view from its container.
            mCustomViewContainer.removeView(mCustomView);
            mCustomView = null;
            mCustomViewContainer.setVisibility(View.GONE);
            mCustomViewCallback.onCustomViewHidden();

            HTML5WebView.this.setVisibility(View.VISIBLE);
            HTML5WebView.this.goBack();
            //Log.i(LOGTAG, "set it to webVew");
        }


        @Override
        public View getVideoLoadingProgressView() {
            //Log.i(LOGTAG, "here in on getVideoLoadingPregressView");

            if (mVideoProgressView == null) {
                LayoutInflater inflater = LayoutInflater.from(mContext);
                mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
            }
            return mVideoProgressView; 
        }

         @Override
         public void onReceivedTitle(WebView view, String title) {
            ((Activity) mContext).setTitle(title);
         }

         @Override
         public void onProgressChanged(WebView view, int newProgress) {
             ((Activity) mContext).getWindow().setFeatureInt(Window.FEATURE_PROGRESS, newProgress*100);
         }

         @Override
         public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
             callback.invoke(origin, true, false);
         }
    }


    static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
        new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}

カスタムスクリーン.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android">
    <FrameLayout android:id="@+id/fullscreen_custom_content"
        android:visibility="gone"
        android:background="@color/black"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    />
    <LinearLayout android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout android:id="@+id/error_console"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
        />

        <FrameLayout android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
        />
    </LinearLayout>
</FrameLayout>

video_loading_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/progress_indicator"
         android:orientation="vertical"
         android:layout_centerInParent="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">

       <ProgressBar android:id="@android:id/progress"
           style="?android:attr/progressBarStyleLarge"
           android:layout_gravity="center"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content" />

       <TextView android:paddingTop="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center"
           android:text="@string/loading_video" android:textSize="14sp"
           android:textColor="?android:attr/textColorPrimary" />
 </LinearLayout>

色.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/http_authentication_colors.xml
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/
-->
<!-- FIXME: Change the name of this file!  It is now being used generically
    for the browser -->
<resources>
    <color name="username_text">#ffffffff</color>
    <color name="username_edit">#ff000000</color>

    <color name="password_text">#ffffffff</color>
    <color name="password_edit">#ff000000</color>

    <color name="ssl_text_label">#ffffffff</color>
    <color name="ssl_text_value">#ffffffff</color>

    <color name="white">#ffffffff</color>
    <color name="black">#ff000000</color>



    <color name="geolocation_permissions_prompt_background">#ffdddddd</color>
</resources>

マニフェスト.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.test"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Test"
                  android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:configChanges="orientation|keyboardHidden|keyboard">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>  
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
</manifest>

あなたが理解できる残りの部分を期待してください。

mdelolmoの答えを口にはセキュリティチェック表示一部のエリアを表示のように彼は言った、映像のみ再度などのオルを設定することができます。

私はこのビットはこちらの見を伺う事ができて勉強にな場合には、疲れWebView旅行者の私のような偶然このポスト。

まずは、ご本人の了解のもと、掲載してい VideoViewMediaPlayer's"文書からよりよい意味でのどのよう。私は強くお勧めします。

そして、ご本人の了解のもと、掲載してい ソースコードをどのようにAndroidのブラウザ います。いページを見に行く見てどのように扱う onShowCustomView().いへの参照 CustomViewCallbackのカスタムビュー。

すべてのことで、mdelolmoの答えは、きっと、だけでいる。第一に、 VideoView ることを行うことができます。への参照、 stopPlayback() このリリース MediaPlayer に使用されます。で見られるように VideoView ソースコード。第二に、 CustomViewCallback を行うことができます。への参照をコ CustomViewCallback.onCustomViewHidden().

後の仕方がないということをクリックするか、同じ映像その他の映像やましんでみてはいかがでしょうか。Noを再起動させる必要があり、全体のWebView.

い役立っています。

実際に、それは単にクライアントビューに株式WebChromeClientを添付するのに十分なようで、ALA

mWebView.setWebChromeClient(new WebChromeClient());

あなたはハードウェアアクセラレーションがオンになっている必要があります!

あなたはフルスクリーンビデオを再生する必要がない場合は、少なくとも、WebViewののVideoViewを引き出し、活動のビューにそれをプッシュする必要はありません。これは、video要素の割り当てられた矩形で再生されます。

拡張ビデオボタンを傍受するためにどのように任意のアイデア?

私は(...まだメディアプレーヤーで)このスレッドは数ヶ月古いですが、私はフルスクリーンそれをやってなくてWebViewの内部の映像を再生するための解決策を見つけた知っています。これまでのところ、私はので、多分これも他の人のために興味深いものですインターネットでこの上の任意のヒントを見つけることができませんでした。 私はまだ(私はそれが間違ってやっている理由を知っていない、すなわち、画面の右側のセクションでメディアプレーヤーを置くが、それは私が考えて、比較的小さな問題...です)いくつかの問題に苦しんでいます。

カスタムChromeClientで LayoutParamsを指定します:

// 768x512 is the size of my video
FrameLayout.LayoutParams LayoutParameters = 
                                     new FrameLayout.LayoutParams (768, 512); 

このような私のonShowCustomView方法のルックスます:

public void onShowCustomView(final View view, final CustomViewCallback callback) {
     // super.onShowCustomView(view, callback);
     if (view instanceof FrameLayout) {
         this.mCustomViewContainer = (FrameLayout) view;
         this.mCustomViewCallback = callback;
         this.mContentView = (WebView) this.kameha.findViewById(R.id.webview);
         if (this.mCustomViewContainer.getFocusedChild() instanceof VideoView) {
             this.mCustomVideoView = (VideoView) 
                                     this.mCustomViewContainer.getFocusedChild();
             this.mCustomViewContainer.setVisibility(View.VISIBLE);
             final int viewWidth = this.mContentView.getWidth();
             final int viewLeft = (viewWidth - 1024) / 2;
             // get the x-position for the video (I'm porting an iPad-Webapp to Xoom, 
             // so I can use those numbers... you have to find your own of course...
             this.LayoutParameters.leftMargin = viewLeft + 256; 
             this.LayoutParameters.topMargin = 128;
             // just add this view so the webview underneath will still be visible, 
             // but apply the LayoutParameters specified above
             this.kameha.addContentView(this.mCustomViewContainer, 
                                             this.LayoutParameters); 
             this.mCustomVideoView.setOnCompletionListener(this);
             this.mCustomVideoView.setOnErrorListener(this);
             // handle clicks on the screen (turning off the video) so you can still
             // navigate in your WebView without having the video lying over it
             this.mCustomVideoView.setOnFocusChangeListener(this); 
             this.mCustomVideoView.start();
         }
     }
 }
私の作業のコードが異なるコード・パーツの野生のミックスだった最後に -

だから、私はあまりにもビデオ・エンコーディングとHTML5のビデオとのWebViewを使用してののこぎり異なる種類の周りにプレイしていた...私は助けることができる願っています私は、インターネットと、私は自分で把握していたいくつかの点で見つかりました。それは本当に*の痛みだった。

このアプローチは非常に2.3までうまく機能します そしてhardwareaccelerated = trueを追加することによって、それも3.0からICSに動作します 私は現在直面しています一つの問題は、私は再生を停止し、メディアプレーヤーをリリースしていないため、メディアプレーヤーアプリケーションの第二の起動がクラッシュしつつある時です。 我々は3.0 OSからonShowCustomView機能で取得VideoSurfaceViewオブジェクトとして、2.3 OSまで、ブラウザと同様ではないVideoViewオブジェクトに固有のものです どのように私はそれとstopPlaybackとリリースのリソースにアクセスすることができますか?

A-Mのは何なのか BrowerActivity います。のための FrameLayout.LayoutParams LayoutParameters=new FrameLayout.LayoutParams(768,512);

るのではないかと考える利用

FrameLayout.LayoutParams LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
            FrameLayout.LayoutParams.FILL_PARENT) 

です。

もう一つの問題は出会った場合の映像を再生し、ユーザの"戻る"ボタンを、次の時間は、以下から入手できますこの活動(singleTop)ができなくなると動画が再生されます。この呼んだときは、

try { 
    mCustomVideoView.stopPlayback();  
    mCustomViewCallback.onCustomViewHidden();
} catch(Throwable e) { //ignore }

この活動のonBackPressed方法です。

私が知っている、これは非常に古い質問ですが、あなたのアプリケーションや活動のためにhardwareAccelerated="true"マニフェストフラグを試してみました?

このセットでは、それがどのWebChromeClientの変更なしで動作しているようです(私はDOM要素から期待。)

私はこのproblem.Downloadを解決して、プロジェクトにあなたをそれを置くために html5webview に使用ただ、このようにコーディングすることができます。

private HTML5WebView mWebView;
String url = "SOMEURL";
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mWebView = new HTML5WebView(this);
    if (savedInstanceState != null) {
            mWebView.restoreState(savedInstanceState);
    } else {
            mWebView.loadUrl(url);
    }
    setContentView(mWebView.getLayout());
}
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mWebView.saveState(outState);
}
あなたの活動にconfigChanges =「向き」のコード:

ビデオ回転可能にするために、アンドロイドを置きます 例えば(のAndroidManifest.xml)

<activity android:name=".ui.HTML5Activity" android:configChanges="orientation"/>

とonConfigurationChangedメソッドをオーバーライドします。

@Override
public void onConfigurationChanged(Configuration newConfig) {
     super.onConfigurationChanged(newConfig);
}

この質問は歳ですが、多分私の答えは、古いAndroidのバージョンをサポートする必要が私のような人々を助けるだろう。しかし私は、すべてではないに、いくつかのAndroidのバージョンで働いていたさまざまなアプローチの多くを試してみました。私が見つけた最高のソリューションを使用することです横断歩道のWebView のアンドロイド4.1上でHTML5機能のサポートと作品のために最適化されていると高いです。これは、デフォルトのAndroidのWebViewとして使用する簡単なようです。あなただけのライブラリを含める必要があります。 :ここでは、それを使用する方法についての簡単なチュートリアルを見つけることができますhttps://diego.org/2015/01/07/embedding-crosswalk-in-android-studio/する

くことができないを使用せずにJNIに登録するプラグインの動画イベントです。(個人的には、私を避け、JNIの来ないんですけも思った混乱が原子に基づくandroidタブレット端末などの今後数ヶ月なので携帯性のJava.)

の代替えする新しいwebページだけでWebViewいビデオを一緒に歩いて、URLのリンクとして引用するCodelark urlです。

ヴ.

ハニカム利用hardwareaccelerated=truepluginstate.on_demandオン

仕事に思えます

私は同様の問題がありました。私は私のアプリの資産フォルダにHTMLファイルやビデオを持っています。

ので動画はAPKの内側に位置していました。 APKが本当にZIPファイルなので、WebViewのは、ビデオファイルを読み取ることができませんでした。

SDカード上にすべてのHTML-およびビデオファイルをコピーするには、私のために働いています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top