I have some WebView code with which I am trying to play YouTube videos on a YouTube channel. But all it is doing is showing the spinner icon on a video and never actually st
Use
<application
android:hardwareAccelerated="true"
android:allowBackup="true">
</application>
Perfectly working.
Have you tried using your own WebChromeClient
? This question seems relevant.
WebView and HTML5 <video>
You'll need to create one of these and implement it yourself, similar to what you're doing for the WebViewClient
.
webview.setWebChromeClient(new WebChromeClient() {
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
if (view instanceof FrameLayout) {
FrameLayout frame = (FrameLayout) view;
if (frame.getFocusedChild() instanceof VideoView) {
VideoView video = (VideoView) frame.getFocusedChild();
frame.removeView(video);
a.setContentView(video);
video.setOnCompletionListener(this);
video.setOnErrorListener(this);
video.start();
}
}
}
});
Make sure you add webview.getSettings().setPluginsEnabled(true);
to your webview settings.
And most importantly, for any webpage to load in a WebView
, be sure to have the INTERNET
permission in your Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
Using WebView to play YouTube videos would require extensive testing and debugging on different Android OS versions due to the difference in functionality and bugs between Android 2.x and 4.x.
A less bug-prone approach that gives you more control is to use YouTube Android Player API to embed a YouTube video into your own app, they have sample app so it shouldn't be too difficult if you follow their steps.