Вопрос

Hi I have a website that has a video player in it, and I want to play that video player insie of my android application. The video player plays great inside of the androids native browser, But when I direct a WebView to go to that same site with the player the video player doesn't show up, All the content around the player shows up. How do I get the video player to play inside of my applications webview?

Это было полезно?

Решение

Webview will not by default allow Javascript which is most likely what your video player is using on the website. You would most likely need to tell your Webview to use Javascript in order for it to at least try to play the video (I say try because I have never done this myself, I usually use a player activity for video).

So by referencing your activies webview object you can do this:

browser = (WebView) findViewById(R.id.webbrowser_wvViewer);    
browser.getSettings().setJavaScriptEnabled(true);

Другие советы

Are you sure your video codec is compatible with Android webview ?

Depending on the browser, the required video codec is different. You can also check this links to debug and see the exact error :

http://www.smartjava.org/content/remote-chrome-debugging-android

Christian, What version of the Android OS are you testing this on?

In Android version Gingerbread and earlier, your WebView based app must implement the WebChromeClient callback in order to be able to play videos. Here is the documentation for WebChromeClient: http://developer.android.com/reference/android/webkit/WebChromeClient.html

Specifically, look at the onShowCustomView() and onHideCustomView callbacks. When playing a video the WebView will callback the onShowCustomView() of the WebChromeClient implementation that you provide. The first param in this callback is a view - which is actually the video that you want to display. The app is expected to override this callback and add this view to the application's window. To summarize, your steps will be as follows: 1. Create a WebView in your app, implement the WebChromeClient in your app and register it using WebView.setWebChromeClient(this). 2. Now your app's onShowCustomView will be called when the user selects play on the video. 3. In your app's implementation of onShowCustomView() you can replace the WebView that is currently displayed by the new View. Do the reverse on onHideCustomView callback. The default implementation for this method is to ignore which is why you are not seeing the video play in your app.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top