I try to play a youtube video in a WebView. So far the video loads but the play button still doesnt work. Embedding the video wont work for me (because many videos simply cannot be played that way because of licencing problems), neither would opening a browser/youtube/whatever. So basically my only other option would be using the Youtube Android API which I find a bit much for a simple task like that.
I checked most answers here but nothing really worked.
Here is the problem in one pic. Clicking on the play button just opens this slider with some like-dislike features, but the video never gets played.
My code is:
w = (WebView)findViewById(R.id.webView1);
w.setWebViewClient(new WebViewClient());
w.setWebChromeClient(new WebChromeClient() {});
w.getSettings().setJavaScriptEnabled(true);
w.loadUrl(url);
Would appreciate any input regarding this
Related
So currently, I've pre-defined URL which I pass to WebView and user is able to watch the video. Problem is that user can also use "search" and switch to other videos after watching the one I defined. Is there a possibility to limit user to watch only one video (while keeping possibility to mute/pause/play video)? Or do I have to implement some Video Player for this use-case?
webView.settings.javaScriptEnabled = true
webView.settings.useWideViewPort = false
webView.loadUrl(url)
Unfortunately it looks like it's no longer possible to hide the video information and related videos when using an embedded player. For more information on why YouTube removed this see https://developers.google.com/youtube/player_parameters#release_notes_08_23_2018
I suggest you take a look at the YouTube Android Player API and try the YouTubeStandalonePlayer or implement YouTubePlayerFragment or YouTubePlayerView.
I am working on developing an in house API that plays some audio. Essentially, I need to drop some embed code in to my application which provides a play/pause button and plays some audio.
I am using a WebView to embed this code in my application. The player seems to appear in the application although when clicking play, I am getting an error the says Play() can only be initiated by a user gesture.
I understand why I am getting this error and why its important to wait for a user gesture. I'd like to adjust my embed code to meet this functionality but am not clear on what I can do to resolve this error and play the audio. Currently, the audio doesn't automatically begin to play, the user must click the play button in the embed code.
Also, whats a bit odd, is that embedding a YouTube video works fine, I am curious as to why YouTube embeds work while my embed doesn't.
The problem in here is in the code embed, not with react-native. Webview has a property called mediaPlaybackRequiresUserAction wich is true by default, try setting it to false to see if it helps
WebView and HTML5 <video> (using Surendra and Malenkiy's answer)
I followed whole above thread and many other articles/question online and got the youtube video to work eventually with webview however it opens in a new intent. I want it to play on the same page within specified web view.
Has someone dealt with something like this. I would appreciate your suggestions.
Thanks.
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.
I have a WebView app that includes embedded YouTube videos on a page. But when I go to that page, it gives me an error with a whole bunch of text. I have searched the internet for the past week but with no luck. Can somebody please help me?
P.S. I am new to Android, so snippets would REALLY help :)
Here's the error:
vp.events.addOnDOMLoadHandler(function()
{vp.website.createVideoPlayer('mediaPlayer_cff30e24_42e1_4eb6
'http://youtube.com/v/XXXX', 569, 485, false);});
You need Flash Player in order to view this.
well from CommonsWare
You cannot show them embedded except perhaps on devices that have Flash.
here is the link: https://stackoverflow.com/a/2292459/1084764
however you can override the urlLoading on your webviewclient
I suggest you reading the whole post : play youtube video in WebView
Check if the Adobe Flash Player on your phone is indeed working properly.