我使用下面的代码在android WebVIEw中播放视频,其中包含一个,我已将视频和海报图像放在资产文件夹中.
vWebvIEw = (WebVIEw)findVIEwByID(R.ID.VWebvIEw);vWebvIEw.getSettings().setJavaScriptEnabled(true);vWebvIEw.getSettings().setPluginsEnabled(true);VIEwContent(raw); inputStream fileStream = getResources().openRawResource(R.raw.test); int fileLen = fileStream.available();byte[] filebuffer = new byte[fileLen]; fileStream.read(filebuffer); fileStream.close(); String displayText = new String(filebuffer);vWebvIEw.loadDataWithBaseURL("fake://not/needed", displayText, "text/HTML", "utf-8", "");
HTML文件是这样的:
<!DOCTYPE HTML><HTML xmlns="http://www.w3.org/1999/xhtml"><head><Meta http-equiv="Content-Type" content="text/HTML; charset=iso-8859-1" /><Title>Hello World</Title><body><div><p><vIDeo src="file:///androID_asset/bigbuck.m4v" poster="file:///androID_asset/test.jpg" onclick="this.play();"/></p></div></body></HTML>
它工作正常.海报图像显示正常,只要我点击它就会出错:
05-12 10:24:22.207: ERROR/http(2882): Null or empty value for header "Host"05-12 10:24:22.207: ERROR/webcoreglue(2882): *** Uncaught exception returned from Java call!05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): Uncaught handler: thread WebVIEwCoreThread exiting due to uncaught exception05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): java.lang.RuntimeException: Null or empty value for header "Host"05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.net.http.Request.addheader(Request.java:161)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.net.http.Request.<init>(Request.java:126)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.net.http.RequestQueue.queueRequest(RequestQueue.java:359)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.net.http.RequestQueue.queueRequest(RequestQueue.java:327)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.webkit.HTML5VIDeoVIEwProxy$PosterDownloader.start(HTML5VIDeoVIEwProxy.java:275)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.webkit.HTML5VIDeoVIEwProxy.loadPoster(HTML5VIDeoVIEwProxy.java:490)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.webkit.WebVIEwCore.nativetouchUp(Native Method)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.webkit.WebVIEwCore.access00(WebVIEwCore.java:48)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.webkit.WebVIEwCore$EventHub.handleMessage(WebVIEwCore.java:1095)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.os.Handler.dispatchMessage(Handler.java:99)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.os.Looper.loop(Looper.java:123)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at androID.webkit.WebVIEwCore$WebCoreThread.run(WebVIEwCore.java:612)05-12 10:24:22.262: ERROR/AndroIDRuntime(2882): at java.lang.Thread.run(Thread.java:1096)
解决方法:
我将视频文件放在RAW文件夹中,并通过以下代码访问default.HTML文件中的视频文件:
vIDeo.src ="androID.resource://ProjectPackageAame/raw/bigbuck"; vIDeo.type = "vIDeo/mp4"; vIDeo.load(); vIDeo.play();
它像我想要的那样播放视频.还在AndroIDManifest文件中添加了以下行.
androID:harDWareAccelerated="true"
试试这个 – where to place local video files for android webview html5 hybrid app
总结以上是内存溢出为你收集整理的如何使用html5在Android Web视图中播放视频全部内容,希望文章能够帮你解决如何使用html5在Android Web视图中播放视频所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)