HTML 5 видео в Webview

Раньше я смотрел видео HTML 5 в webview, и оно работало нормально. Но вдруг он перестал работать и дает мне следующее исключение:

01-30 18:56:18.599: E/Web Console(16923): Uncaught ReferenceError: PresentationPlayer is not defined:48

Пожалуйста, помогите мне. Я не знаю, что я здесь сделал не так. Ниже мой код для воспроизведения видео:

HTML5WebView mWebView;
ActionBar actionBar;
AlertDialog alertDialog;
Activity activity;
public static String url;
protected void onCreate(android.os.Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();

    url = intent.getStringExtra(BConstant.TRAINING_VIDEO_URL);
    activity = (Activity) ProductTrainingActivity.this;
    actionBar = getActionBar();
    actionBar.hide();
    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);
}

@Override
protected void onPause() {
    super.onPause();
    mWebView.stopLoading();
}

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

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

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

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

@Override
public void onBackPressed() {
    if (mWebView.isFocused() && mWebView.canGoBack()) {
        mWebView.goBack();

    } else {
        super.onBackPressed();
        activity.finish();
    }
}

HTML5WebView

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";

HttpClient httpClient;

@SuppressLint("SetJavaScriptEnabled")
private void init(Context context) {
    mContext = context;
    Activity activity = (Activity) mContext;                
    mLayout = new FrameLayout(context);

    mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(activity)
            .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 webSettings = getSettings();
    webSettings.setBuiltInZoomControls(true);
    webSettings
            .setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    // s.setSavePassword(true);
    webSettings.setSaveFormData(true);
    webSettings.setJavaScriptEnabled(true);

    webSettings.setPluginState(PluginState.ON);
    mWebChromeClient = new MyWebChromeClient();
    setWebChromeClient(mWebChromeClient);
    //setWebViewClient(new WebViewClient());
     this.setWebViewClient(new WebViewClient() {
     @Override
     public boolean shouldOverrideUrlLoading(WebView view, String url) {
         System.out.println(url);
         System.out.println(additionalHttpHeaders);
     view.loadUrl(url, additionalHttpHeaders);
     return true;
     }
     });
    // setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    setScrollBarStyle(View.MEASURED_SIZE_MASK);

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

    // enable Web Storage: localStorage, sessionStorage
    webSettings.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 View mVideoProgressView;

    @Override
    public void onShowCustomView(View view,
            WebChromeClient.CustomViewCallback callback) {
        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() {
        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();
    }

    @Override
    public View getVideoLoadingProgressView() {

        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);

}

Спасибо за рассмотрение.

0 ответов

Другие вопросы по тегам