title: Youtube iframe api check if video exists
body: <p>I am working on a simple page that has a text input where the user can add the id of the youtube video they want to insert into the page, then I call youtube's iframe api to load the video. However, if the user adds an id that does not exists I get a black screen.</p>
  
  <p>I was hoping someone knows a way of checking if the video exists before loading it.</p>
  
  <p>This is my code:</p>
  
  <pre><code>$(document).ready(function() {
    $('#loadVid').click(function() {
       var player;
       var urlVid = $('#urlVid').val(); //GET THE VIDEO CODE FROM THE TEXT INPUT
  
       player = new YT.Player('player', {
            height: '390',
            width: '640',
            videoId: urlVid,
            events: {
              'onReady': onPlayerReady,
              'onStateChange': onPlayerStateChange
            }
       });
    });
  });
  </code></pre>