Embedding a video with YouTube API results in 404 error

时间:2015-07-28 22:27:06

标签: javascript iframe youtube

I'm trying to embed a video on my site (we own the video) using YouTube's API rather than creating an iframe from the outset. When I provide the videoId, it gives me a 404 error on the video. But when I create an iframe and use the ID in the url, it works correctly and finds the video.

Here's the player create code:

function onYouTubeIframeAPIReady() {
        player = new YT.Player('videoPlayer', {
          height: '720',
          width: '1280',
          videoId: 'jQo4HLEwutg',
          playerVars: {'controls':0, rel: 0, 'showinfo': 0, 'modestbranding': 1, 'enablejsapi': 1, 'origin': 'https://www.mycompany.com' },
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      }

The 404 is this, specifically:

"NetworkError: 404 Not Found - https://www.youtube.com/get_video?noflv=1&video_id=jQo4HLEwutg&cpn=FnysBfLg7QmW1DiI&el=embedded&referrer&eurl=https%3A%2F%2Flocalhost%3A444%2F&fmt=134&ptk=youtube_none&splay=1"

Using a standard iframe, this works:

<iframe id="videoFrame" src="https://www.youtube.com/embed/jQo4HLEwutg?enablejsapi=1&origin=https://www.mycompany.com&rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>

Why does the same video ID work when using it in the iframe URL but not as a param in the function?

(This is my first time trying to use the API; sorry if I'm missing something obvious.)

1 个答案:

答案 0 :(得分:1)

Following https://developers.google.com/youtube/iframe_api_reference you can setup your video to work. I tried with the video params on your player object and it did work. Try to run your page on your server. http://jsbin.com/tazocariqu