0
import com.google.ads.AdRequest;

import com.google.ads.AdView;

import android.os.Bundle;

import android.app.Activity;

import android.graphics.Bitmap;

import android.view.Menu;

import android.view.View;

import android.webkit.WebView;

import android.webkit.WebViewClient;

import android.widget.ProgressBar;

public class Youtube extends Activity {

    private WebView webView;

    private ProgressBar progress;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_youtube);


        webView = (WebView) findViewById(R.id.webView4);

        webView.setWebViewClient(new MyWebViewClient());

        progress = (ProgressBar) findViewById(R.id.progressBar4);

        webView.getSettings().setJavaScriptEnabled(true);

        webView.loadUrl("http://www.youtube.com/");
    }

    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        //getMenuInflater().inflate(R.menu.ver_web, menu);

        return true;
    }

    private class MyWebViewClient extends WebViewClient {  

        @Override

        public boolean shouldOverrideUrlLoading(WebView view, String url) {

               view.loadUrl(url);

               return true;
        }

        @Override

        public void onPageFinished(WebView view, String url) {

            progress.setVisibility(View.GONE);

            Youtube.this.progress.setProgress(100);

            super.onPageFinished(view, url);

       }

        @Override

       public void onPageStarted(WebView view, String url, Bitmap favicon) {

           progress.setVisibility(View.VISIBLE);

           Youtube.this.progress.setProgress(0);

           super.onPageStarted(view, url, favicon);
       }
   }

   public void setValue(int progress) {

       this.progress.setProgress(progress);       
   }

   @Override

   public void onBackPressed() {

       // Check if there's history

       if (this.webView.canGoBack())

           this.webView.goBack();

       else

           super.onBackPressed();

   }

public void onCreate1(Bundle savedInstanceState) {


//Request an ad

AdView ad = (AdView) findViewById(R.id.adView);

ad.loadAd(new AdRequest());

}

}
jmj
  • 237,923
  • 42
  • 401
  • 438
  • 1
    Take a look at http://stackoverflow.com/questions/17706580/youtube-video-not-playing-in-webview – Glauco Neves Feb 23 '14 at 19:53
  • So what exactly is going wrong? How are you entering the URL? And have you used a debugger to check whether `view.loadUrl` is actually getting called? – Dawood ibn Kareem Feb 23 '14 at 21:23
  • No, it's unfair to close this as a duplicate. If you look at the only answer to that other question, the OP clearly stated that it didn't work. It looks like he/she may have only accepted the answer out of charity. It seems doubtful therefore, that this question has a working answer yet. Voting to reopen. – Dawood ibn Kareem Feb 24 '14 at 03:02
  • @DavidWallace that question was accepted because it provided answer to the original question and also provided answers to couple of more questions in the comments. Please read all the comments. – Alex P Feb 27 '14 at 22:32
  • @AlexP I read them all, thank you, before I voted to reopen this question. – Dawood ibn Kareem Feb 27 '14 at 22:36

0 Answers0