YouTube videos do not play in A web view on Android 4.0, but in 6.0 the videos run normally. I have already done a lot of research on this topic, but I have not found any practical answers to my very low knowledge about Android development. If someone is able to help me how to play YouTube videos in a web view, please be clear. Here's my code:
pagina.loadUrl("https://www.google.com/");
pagina.getSettings().setJavaScriptEnabled(true);
pagina.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
pagina.setWebViewClient(new WebViewClient(){
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
super.onPageStarted(view, url, favicon);
Barra.setText(url);
pb.setVisibility(View.VISIBLE);}
@Override
public void onPageFinished(WebView view, String url)
{
pb.setVisibility(View.INVISIBLE);}});
pagina.setDownloadListener(new DownloadListener(){
@SuppressLint("InlinedApi")public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength)
{
DownloadManager.Request request =new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();final String filename =URLUtil.guessFileName(url, contentDisposition, mimetype);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
request.setDestinationInExternalPublicDir("/Download", filename);DownloadManager dm =(DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);Intent intent =new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
Toast.makeText(getApplicationContext(), "Download iniciado",
Toast.LENGTH_LONG).show();}});
proximo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
if (pagina.canGoForward())
{
pagina.goForward();}
else
{
Toast toast=Toast.makeText(getApplicationContext(), "Não há paginas para avançar", Toast.LENGTH_SHORT);
toast.show();
}}});
Ir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
pagina.loadUrl(Barra.getText().toString());}});
voltar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
if (pagina.canGoBack())
{
pagina.goBack();}
else
{
Toast toast=Toast.makeText(getApplicationContext(), "Não há paginas para voltar", Toast.LENGTH_SHORT);
toast.show();
}}});
reload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
pagina.reload();
};});}}