title: YouTube JS API Custom Player Skip/Next Video Function
body: <p>I have a custom youtube player coded mostly in javascipt/jQuery that uses the iframe method and has next and previous track buttons that work without using the YouTube JavaScript API functions.  The player also changes the ID of the video playing based on the search result link clicked on by the user. The only problem I Have is that I need to be able to detect when the video that is currently playing ends so the player will know when to skip to the next track on the list without requiring the user to click a button.  Is this possible to do without the API calls?  </p>
  
  <p>If not, how should I go about implementing the YouTube iframe embed using the JavaScript API to determine when the song has ended via the OnStateChange event, while still being able to change the ID of the song playing when a user clicks on a search result link?</p>
  
  <p>Should this be done by passing the video ID to the function creating the YouTube player object, then destroying it when a user clicks on a link and inserting a new instance of the YouTube player with the new ID?</p>