2017-06-15 1 views
1

Je veux afficher YouTube vidéos dans mon application et pour cela, je veux utiliser WebView.
Pour une utilisation WebView et vidéos de montrer que je le ci-dessous les codes:Comment afficher la vidéo YouTube dans webView sur Android

  WebSettings settings = content_newsWebView.getSettings(); 
      content_newsWebView.setWebChromeClient(new WebChromeClient()); 
      content_newsWebView.getSettings().setDomStorageEnabled(true); 
      content_newsWebView.getSettings().setAppCacheEnabled(true); 
      content_newsWebView.getSettings().setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache"); 
      content_newsWebView.getSettings().setDatabaseEnabled(true); 
      content_newsWebView.getSettings().setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases"); 
      settings.setPluginState(WebSettings.PluginState.ON); 
      content_newsWebView.getSettings().setJavaScriptEnabled(true); 
      settings.setDefaultTextEncodingName("utf-8"); 
      content_newsWebView.loadData(response.body().getData().getDescription(), "text/html; charset=UTF-8", null); 

Quand exécuter l'application, montrez-moi la vidéo mais pas sensibles!
Montrez-moi la vidéo la plus grande! S'il vous plaît voir cette image pour comprendre mes moyens: Image Link

Je veux afficher vidéo responsive Youtube dans mon application.

Je reçois un lien vidéo depuis un serveur avec ce Json:

> "<p><iframe frameborder=\"0\" 
> src=\"https://www.youtube.com/embed/NcoBDgJ3ZBw\" 
> style=\"width:100%;min-height: 400px;\"></iframe></p>\n\n<p>The Harry 
> Potter star plays an Israeli backpacker in the upcoming thriller from 
> <a 
> href=\"http://example.com/Celebrities/276442/greg_mclean\"><strong>Greg McLean</strong></a> (<a 
> href=\"http://example.com/Movies/94393/the_belko_experiment\"><strong>The 
> Belko Experiment</strong></a>, <a 
> href=\"http://example.com/Movies/1397/wolf_creek\"><strong>Wolf 
> Creek</strong></a>).</p>\n\n<p><a 
> href=\"http://example.com/Celebrities/10139/daniel_radcliffe\"><strong>Radcliffe</strong></a>, 
> 27, is a young adventurer going on a dream trip into the Amazonian 
> rain forest along with two friends and a mysterious guide named 
> Karl.</p>\n\n<p>Abandoned by their guide among the dangerous jungle 
> creatures, Yossi (<a 
> href=\"http://example.com/Celebrities/10139/daniel_radcliffe\"><strong>Radcliffe</strong></a>) 
> and his friends are left with little means to survive, ending up in 
> psychological battles with themselves.</p>\n\n<p>Starring <a 
> href=\"http://example.com/Celebrities/64592/alex_russell\"><strong>Alex Russell</strong></a>, <a 
> href=\"http://example.com/Celebrities/53829/thomas_kretschmann\"><strong>Thomas 
> Kretschmann</strong></a> and <strong>Yasmin Kassim</strong>, Jungle 
> premiers at Melbourne International Film Festival on Aug. 3.</p>\n" 

Comment puis-je montrer réactif youtube vidéo dans mon application?

S'il vous plaît aidez-moi les gars, J'ai vraiment besoin de vos aides.

+1

double possible de [Lire la vidéo intégrée Youtube HTML5 dans Android WebView] (https://stackoverflow.com/questions/6323169/play-youtube-html5-embedded-video-in-android-webview) –

+0

@ KaranSharma, je l'essaie mais ne fonctionne pas moi –

+0

le json que vous avez fourni est le mauvais format –

Répondre

0

Essayez le code suivant: Modifier l'URL de la vidéo dans la chaîne.

String frameVideo = "<html><body>Video From YouTube<br><iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/47yJ2XCRLZs\" frameborder=\"0\" allowfullscreen></iframe></body></html>"; 

    WebView displayYoutubeVideo = (WebView) findViewById(R.id.mWebView); 
    displayYoutubeVideo . setWebViewClient (New WebViewClient() { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      return false; 
     } 
    }); 
    WebSettings webSettings = displayYoutubeVideo . getSettings(); 
    webSettings.setJavaScriptEnabled(true); 
    displayYoutubeVideo.loadData(frameVideo, "text/html", "utf-8"); 
+0

merci mon ami, pouvez-vous éditer vos codes avec mes codes ci-dessus? S'il te plaît, je suis amateur. S'il vous plaît –

+0

vous pouvez utiliser ce code indépendamment et vous pouvez faire des changements en plus de cela en fonction de vos besoins –