html视频没有在android webview中播放

html视频没有在android webview中播放,第1张

概述我正在使用 android webview,在这里我坚持使用视频.实际上我正在尝试播放资产文件夹中的视频,但它没有播放. 在这里,我已经完成了所有的链接和解决方案,但没有什么对我有用 – 比如 [LINK1] [1] https://code.google.com/p/html5webview/source/browse/trunk/HTML5WebView/src/org/itri/html5w 我正在使用 android webvIEw,在这里我坚持使用视频.实际上我正在尝试播放资产文件夹中的视频,但它没有播放.
在这里,我已经完成了所有的链接和解决方案,但没有什么对我有用 – 比如

[link1] [1]
https://code.google.com/p/html5webview/source/browse/trunk/HTML5WebView/src/org/itri/html5webview/TestHTML5WebView.java

[link2] [2]
http://www.mocoven.com/blog/?p=199

以下我附上代码 –

// HTML5webvIEw

package com.example.jbb_vIDeo_play;import androID.annotation.Suppresslint;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";        @Suppresslint("NewAPI")        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);                mWebChromeClIEnt = new MyWebChromeClIEnt();            setWebChromeClIEnt(mWebChromeClIEnt);            setWebVIEwClIEnt(new MyWebVIEwClIEnt());            // Configure the webvIEw            WebSettings s = getSettings();            s.setBuiltInZoomControls(true);            s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_ColUMNS);            s.setUseWIDeVIEwPort(true);            s.setAllowContentAccess(true);            s.setAllowfileAccess(true);            s.setAllowUniversalAccessFromfileURLs(true);            s.setAllowfileAccessFromfileURLs(true);            s.setmediaplaybackRequiresUserGesture(true);            s.setNeedInitialFocus(true);            s.setSaveFormData(true);            s.setUserAgentString(getUrl());            s.setLoadsImagesautomatically(true);            s.setBlockNetworkLoads(false);            s.setBlockNetworkImage(false);            s.setDatabaseEnabled(true);            s.setJavaScriptCanopenwindowsautomatically(true);            s.setJavaScriptEnabled(true);            s.setSupportMultiplewindows(true);            s.setLoaDWithOverviewmode(true);            s.setSavePassword(true);            s.setSaveFormData(true);            s.setJavaScriptEnabled(true);            // 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() {                        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);                //Log.i(LOGTAG,"set it to webVew");                }                @OverrIDe                public Bitmap getDefaultVIDeoPoster() {                        //Log.i(LOGTAG,"here in on getDefaultVIDeoPoster");                            if (mDefaultVIDeoPoster == null) {                                mDefaultVIDeoPoster = BitmapFactory.decodeResource(                                                getResources(),R.drawable.ic_launcher);                    }                        return mDefaultVIDeoPoster;                }                @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);         }    }        private class MyWebVIEwClIEnt extends WebVIEwClIEnt {            @OverrIDe            public boolean shouldOverrIDeUrlLoading(WebVIEw vIEw,String url) {                Log.i(LOGTAG,"shouldOverrIDeUrlLoading: "+url);                // don't overrIDe URL so that stuff within iframe can work properly                // vIEw.loadUrl(url);                return false;            }        }        static final FrameLayout.LayoutParams COVER_SCREEN_ParaMS =        new FrameLayout.LayoutParams( VIEwGroup.LayoutParams.MATCH_PARENT,VIEwGroup.LayoutParams.MATCH_PARENT);}


//主要活动

public class MainActivity extends Activity {    HTML5WebVIEw mWebVIEw;   @OverrIDe   public voID onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       mWebVIEw = new HTML5WebVIEw(this);       if (savedInstanceState != null) {               mWebVIEw.restoreState(savedInstanceState);       } else {           try        {        AssetManager m=this.getAssets();        inputStream ios=    m.open("nasa.HTML");        BufferedReader br=new BufferedReader(new inputStreamReader(ios));        StringBuffer nb=new StringBuffer();        String line="";        while((line=br.readline())!=null)        {            nb.append(line);        }        String final_data=nb.toString();        //mWebVIEw.loadDataWithBaseURL("file:///androID_asset/",final_data,"text/HTML","utf-8",null);              // mWebVIEw.loadUrl("http://freebsd.csIE.nctu.edu.tw/~freedom/HTML5/");               mWebVIEw.loadUrl("file:///androID_asset/nasa.HTML");        }           catch (Exception e) {            // Todo: handle exception        }       }       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();                return true;            }        }        return super.onKeyDown(keyCode,event);    }    @OverrIDe    public voID onConfigurationChanged(Configuration newConfig) {         super.onConfigurationChanged(newConfig);    }}

//资产文件夹中的HTML文件

<!DOCTYPE HTML><head></head><body><vIDeo ID="vIDeo" height="240" wIDth="360" controls="controls" ><source src="clipcanvas_14348_offline.mp4" type="vIDeo/mp4"></vIDeo></body><footer></footer>

和视频链接

http://www.clipcanvas.com/a/video-clip-downloads/

请建议我任何可行的解决方案,谢谢

解决方法 当视频位于div中时,您应该在代码中添加以下行:
webVIEw.getSettings().setDomStorageEnabled(true);    webVIEw.getSettings().setAppCacheEnabled(true);    webVIEw.getSettings().setAppCachePath(getApplicationContext().getfilesDir().getabsolutePath() + "/cache");    webVIEw.getSettings().setDatabaseEnabled(true);    webVIEw.getSettings().setDatabasePath(getApplicationContext().getfilesDir().getabsolutePath() + "/databases");
总结

以上是内存溢出为你收集整理的html视频没有在android webview中播放全部内容,希望文章能够帮你解决html视频没有在android webview中播放所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1139726.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存