私のシナリオを説明しましょう。Youtube IFrame APIを使用して、自分のWebサイトにいくつかのビデオを埋め込みたいです。このページでIDwdGZBRAwW74(https://www.youtube.com/watch?v=wdGZBRAwW74 )のビデオをテストしました: Youtube IFramePlayerDemo 。そして、それは問題なく動作します。
このサンプルコードを試してみます:
<!DOCTYPE html>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'wdGZBRAwW74',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError': onPlayerError
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function onPlayerError(event){
console.log(event.data);
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>
私のローカルホストにいくつかの仮想ホストドメインがあり、結果が得られました:
- ドメインapp.centaur.com/youtube/index.htmの場合:IFrame APIは正常に機能し、ビデオは問題なく再生されます。
- ドメインapp.music.com/youtube/index.htmlの場合:IFrame APIは正常に機能しますが、動画を再生できません。APIはエラー150でonErrorを起動し、埋め込みプレーヤーに「この動画には、ブロックしたVEVOのコンテンツが含まれています。このウェブサイトの表示から。Youtubeで見る"
- ドメインapp.musiccentaur.com/youtube/index.htmの場合:最初のケースと同様に、すべてが正常に機能します
- ドメインapp.centaurmusic.com/youtube /の場合:最初のケースと同様に、すべてが正常に機能します
私が知っているように、エラー150は、「要求されたビデオの所有者は、埋め込みプレーヤーでの再生を許可していません」を表します。しかし、ケース1、3、4でも機能するようですが、どういう意味ですか?
この問題に関連するVevoのすべてのビデオのようです。Vevoが動画を埋め込むためのポリシーを定義したかどうかはわかりません。
問題は私のドメインmusic.comにあるのかもしれませんが、VevoのビデオをWebサイトに埋め込むためのドメインのルールがあるかどうかはわかりません。
ウェブサイトのドメインを購入した場合、エラー150が発生しますが、これは非常に悪いことです。:(
以前にこれに対処した人はいますか?解決策を教えてください。前もって感謝します。
注:このエラーはVevoのビデオでのみ発生します。