Android - WebView not playing YouTube videos
android, android-webview, webview
Solution
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.
Problem
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 starting the video. Would anyone know how to fix that? ``` public class YoutubeActivity extends Activity { WebView webview = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); webview = new WebView(this); webview.getSettings().setAppCacheEnabled(false); webview.getSettings().setJavaScriptEnabled(true); webview.setInitialScale(1); webview.getSettings().setPluginState(PluginState.ON); webview.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); //webSettings.getMediaPlaybackRequiresUserGesture(); webSettings.setAllowContentAccess(true); webSettings.setEnableSmoothTransition(true); webSettings.setLoadsImagesAutomatically(true); webSettings.setLoadWithOverviewMode(true); webSettings.setSupportZoom(true); webSettings.setUseWideViewPort(true); setContentView(webview); webview.loadUrl("http://www.youtube.com/g33ktalktv"); } public void onBackPressed ( ) { //Class.forName("com.***.HTML5WebView").getMethod("onPause", (Class[]) null). //invoke(html5WebView, (Object[]) null); webview.clearView(); } @Override public void onStop() { super.onStop(); // your code webview.clearView(); } } ``` And this is the manifest setting: ``` <activity android:name="YoutubeActivity" android:label="Some string" android:hardwareAccelerated="true"/> ``` Thannk in advance!