Thursday, August 17, 2017

Not able to view video in Android Web View

Leave a Comment

My web pages have emebedded video files using html5 video tags.

I have an embedded web server (NanoHTTPD) running which serves my file from file system. Everything else works but when i click on play of the HTML5 video. It gives the following error and the video is not played

  09-29 20:38:36.620: D/HTML5VideoInline(11532): HTML5VideoInline created 09-29 20:38:36.625: V/MediaPlayer(11532): setVideoSurfaceTexture 09-29 20:38:36.625: V/MediaPlayer-JNI(11532): reset 09-29 20:38:36.625: V/MediaPlayer(11532): reset 09-29 20:38:36.625: I/MediaPlayer(11532): path is null 09-29 20:38:36.640: D/MediaPlayer(11532): setDataSource IOException happend :  09-29 20:38:36.640: D/MediaPlayer(11532): java.io.FileNotFoundException: No content provider: http://10.207.114.115:8765/SLC/Book3_html/Book3/book/BO/demo.mp4 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:713) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:617) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.media.MediaPlayer.setDataSource(MediaPlayer.java:954) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.webkit.HTML5VideoView.prepareDataCommon(HTML5VideoView.java:326) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.webkit.HTML5VideoView.prepareDataAndDisplayMode(HTML5VideoView.java:363) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.webkit.HTML5VideoInline.prepareDataAndDisplayMode(HTML5VideoInline.java:72) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.webkit.HTML5VideoViewProxy$VideoPlayer.play(HTML5VideoViewProxy.java:289) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.webkit.HTML5VideoViewProxy.handleMessage(HTML5VideoViewProxy.java:465) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.os.Handler.dispatchMessage(Handler.java:99) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.os.Looper.loop(Looper.java:137) 09-29 20:38:36.640: D/MediaPlayer(11532):   at android.app.ActivityThread.main(ActivityThread.java:5306) 09-29 20:38:36.640: D/MediaPlayer(11532):   at java.lang.reflect.Method.invokeNative(Native Method) 09-29 20:38:36.640: D/MediaPlayer(11532):   at java.lang.reflect.Method.invoke(Method.java:511) 09-29 20:38:36.640: D/MediaPlayer(11532):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 09-29 20:38:36.640: D/MediaPlayer(11532):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 09-29 20:38:36.640: D/MediaPlayer(11532):   at dalvik.system.NativeStart.main(Native Method) 09-29 20:38:36.640: D/MediaPlayer(11532): Couldn't open file on client side, trying server side 

The media player goes to Content resolver which tries to load only files of content scheme. My uris are of http scheme.

My web view is plain simple one.

WebSettings webViewSettings = webView.getSettings();     webViewSettings.setJavaScriptEnabled(true);     //webViewSettings.setJavaScriptCanOpenWindowsAutomatically(false);     //webViewSettings.setSupportMultipleWindows(true);     webViewSettings.setPluginState(PluginState.ON);     //webViewSettings.setMediaPlaybackRequiresUserGesture(false);     webViewSettings.setAllowFileAccess(true);     webView.setSoundEffectsEnabled(true);     //webViewSettings.setSupportZoom(true);     //WebView.setWebContentsDebuggingEnabled(true);      webView.setWebViewClient(new CustomWebViewClient());     webView.setWebChromeClient(mWebChromeClient); 

cheers, Saurav

2 Answers

Answers 1

You need to use loadDataWithBaseURL.

See this: https://stackoverflow.com/a/24592012/850347

DON'T do this:

mContentWebView.loadDataWithBaseURL(null, webViewContentString,         "text/html", "UTF-8", null); 

DO THIS INSTEAD:

//veryVeryVery important for playing the videos! mContentWebView.loadDataWithBaseURL(theBaseUrl, webViewConentString,         "text/html", "UTF-8", null); 

Answers 2

It seems you have an issue setting setDataSource(), make sure you are calling

setDataSource(String path)

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment