Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:33:40+00:00 2026-06-03T07:33:40+00:00

I am trying to use the YouTube API to detect when a video ends

  • 0

I am trying to use the YouTube API to detect when a video ends and then to call a JS function I have to then load another one. The call function is in another JS document which is in the head of my HTML document.
This is the code I have so far from the API site but I am really confused with it.

<pre><code> <script>




var ytfullplayer;
    function onYouTubePlayerAPIReady() {
        console.log('onYouTubePlayerAPIReady');
        ytfullplayer = new YT.Player('myVid', {
            events: {

              if ''onStateChange': getVideo

            }
        });

    }
    function getVideo(); }


</script> </code> </pre>

I have called the youtube api in the head of my page. But I am not 100% sure if it goes there.
Any assistance would be nice.
I am using an for my youtube video.

Cheers
Matt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:33:41+00:00Added an answer on June 3, 2026 at 7:33 am

    The API provides an example of what you’re attempting beneath Subscribing to Events:

    function onYouTubePlayerReady(playerId) {
      ytplayer = document.getElementById("myytplayer");
      ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
    }
    
    function onytplayerStateChange(newState) {
       alert("Player's new state: " + newState);
    }
    

    Bind your custom function as the handler to the “onStateChange” event, and evaluate the new state from within. According to the Events portion of the API, you’re looking for state 0, indicating the video has ended.

    function onytplayerStateChange(newState) {
       if ( newState == 0 ) {
         /* load next video */
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use my own function (never liked $(document).ready() ) to dynamically load
Is there a definitive gem for the YouTube API? I'm trying to use youtube_g,
Okay so what i am trying to achieve is use the youtube api to
I am trying to use the youtube API to pulldown some videos for my
I'm trying to use youtube's api to bring back a listing of a user's
I'm trying to use youtube's data api to search where the search term includes
Fiddle link: http://jsfiddle.net/T35fH/ Hi! I m trying to have 2 iframe youtube video player
I'm trying to use the youtube javascript player api to embed youtube videos into
I'm trying to use the YouTube API to control several you-tube videos. And I'm
I'm trying to use the Youtube .Net API in F# and I've come across

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.