title: Play facebook video url in Android
body: <p>I am trying to play the facebook video url in <strong>videoView</strong> as well as in <strong>webview</strong> like this:-</p>
  
  <p><strong>1. In VideoView</strong></p>
  
  <pre><code>    VideoView videoView = (VideoView) findViewById(R.id.videoView);
       //Use a media controller so that you can scroll the video contents
       //and also to pause, start the video.
       MediaController mediaController = new MediaController(this);
       mediaController.setAnchorView(videoView);
       videoView.setMediaController(mediaController);
       videoView.setVideoURI(Uri.parse("https://www.facebook.com/video/embed?video_id=641390085951248"));
       videoView.start();
  </code></pre>
  
  <p><strong>2. In WebView</strong></p>
  
  <pre><code>    WebView webView = (WebView) findViewById(R.id.webView);
      final WebSettings settings = webView.getSettings();
      settings.setDefaultTextEncodingName("utf-8");
      settings.setJavaScriptEnabled(true);
      webView.loadUrl("https://www.facebook.com/video/embed?video_id=641390085951248");
  </code></pre>
  
  <p>and also define Internet Permission in manifest file.</p>
  
  <p>But I unable to play my facebook videoUrl.</p>
  
  <p>Please Comment on it.</p>
  
  <p>Hello Guys,I found a VideoPlayer Code and Run it, but unable to play a video from it.</p>
  
  <pre><code>public class VideoPlayer extends Activity {
  
      ProgressDialog mProgress;
      VideoView video;
      int second;
      static int length;
      Button replay_button;
      OnCancelListener oncancel;
  
      /*
       * PowerManager manager; PowerManager.WakeLock wl;
       */
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.video_player);
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
          String url = getIntent().getStringExtra("url");
          video = (VideoView) findViewById(R.id.videoView1);
  
          /*
           * manager = (PowerManager) getSystemService(Context.POWER_SERVICE); wl
           * = manager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
           * "Your Tag"); wl.acquire();
           */
  
          replay_button = (Button) findViewById(R.id.replayButton);
  
          oncancel = new OnCancelListener() {
  
              @Override
              public void onCancel(DialogInterface dialog) {
                  // TODO Auto-generated method stub
                  finish();
              }
          };
  
          try {
              mProgress = new ProgressDialog(VideoPlayer.this);
  
          } catch (Exception e) {
              // TODO: handle exception
          }
  
          MediaController mediaController = new MediaController(VideoPlayer.this);
          mediaController.setAnchorView(video);
          video.setMediaController(mediaController);
          video.setKeepScreenOn(true);
          video.setVideoPath(url);
          video.requestFocus();
          video.start();
          video.setOnTouchListener(new OnTouchListener() {
  
              @Override
              public boolean onTouch(View arg0, MotionEvent arg1) {
                  // TODO Auto-generated method stub
                  replay_button.setVisibility(View.GONE);
                  return false;
              }
          });
  
          video.setOnPreparedListener(new OnPreparedListener() {
  
              @Override
              public void onPrepared(MediaPlayer mp) {
                  // TODO Auto-generated method stub
                  try {
                      if (mProgress != null) {
                          mProgress.dismiss();
                      }
  
                      video.start();
  
                  } catch (Exception e) {
                      // TODO: handle exception
  
                  }
  
              }
          });
          DialogInterface.OnCancelListener cancel = new OnCancelListener() {
  
              @Override
              public void onCancel(DialogInterface dialog) {
                  // TODO Auto-generated method stub
                  finish();
  
              }
          };
  
          video.setOnErrorListener(new OnErrorListener() {
  
              @Override
              public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
                  // TODO Auto-generated method stub
                  try {
                      showMessage("Message", "Sorry,This Video can not be played.");
                  } catch (Exception e) {
                      // TODO: handle exception
                  }
  
                  return true;
              }
          });
  
          video.setOnCompletionListener(new OnCompletionListener() {
  
              @Override
              public void onCompletion(MediaPlayer arg0) {
                  // TODO Auto-generated method stub
                  try {
  
                      replay_button.setVisibility(View.VISIBLE);
                      replay_button.setOnClickListener(new OnClickListener() {
  
                          @Override
                          public void onClick(View arg0) {
                              // TODO Auto-generated method stub
  
                              video.start();
                              replay_button.setVisibility(View.GONE);
                          }
                      });
  
                  } catch (Exception e) {
                      // TODO: handle exception
                  }
  
              }
          });
  
          /*
           * timess tiktok = new timess(1000000000, 1000); tiktok.start();
           */
  
      }
  
      @SuppressLint("NewApi")
      @Override
      public void onBackPressed() {
          // TODO Auto-generated method stub
          super.onBackPressed();
          // Log.i(" back key pressed","keyPressed");
          try {
              if (mProgress != null) {
                  mProgress.dismiss();
              }
          } catch (Exception e) {
              // TODO: handle exception
          }
          // wl.release();
          finish();
  
      }
  
      @Override
      protected void onPause() {
          // TODO Auto-generated method stub
          super.onPause();
          video.pause();
      }
  
      @Override
      protected void onRestart() {
          // TODO Auto-generated method stub
          video.start();
          super.onRestart();
      }
  
      @Override
      public void onResume() {
          super.onResume();
          replay_button.setVisibility(View.GONE);
      }
  
      private void showMessage(String title, String message) {
          try {
              AlertDialog.Builder alt_bld = new AlertDialog.Builder(VideoPlayer.this);
              alt_bld.setTitle(title);
              alt_bld.setMessage(message);
              alt_bld.setCancelable(false);
              alt_bld.setNeutralButton("OK", new DialogInterface.OnClickListener() {
  
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      // TODO Auto-generated method stub
                      finish();
                      dialog.dismiss();
  
                  }
              });
              alt_bld.show();
          } catch (Exception e) {
              // TODO: handle exception
          }
      }
  }
  </code></pre>