English 中文(简体)
在录像结束后,让一个嵌入的YouTube角色脱掉
原标题:Get rid of an embedded YouTube player after video has finished
  • 时间:2012-05-18 12:14:32
  •  标签:
  • youtube

目前,我有以下的密码,可以在一页上播放你的录音录像。

<div id="player"></div>
<script>
//Load player api asynchronously.
var tag = document.createElement( script );
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName( script )[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
    player = new YT.Player( player , {
      height:  390 ,
      width:  640 ,
      videoId:  JW5meKfy3fY ,
      playerVars: {  autoplay : 1,  rel : 0,  showinfo : 0,  egm : 0,  showsearch : 0, },
      events: {
         onReady : onPlayerReady,
         onStateChange : onPlayerStateChange
      }
    });
}
function onPlayerReady(event) {
    event.target.playVideo();
}
function onPlayerStateChange(event) {
    //When the video has ended
    if (event.data == YT.PlayerState.ENDED) {
        //Get rid of the player
    }
}

The onPlayerStateChange function finds out when the player has finished playing the video. How can I then make this player disappear?

问题回答

如果您正在使用IFRAME LANES,

function onPlayerStateChange(event) {
    //When the video has ended
    if (event.data == YT.PlayerState.ENDED) {
        //Get rid of the player
        event.target.destroy();
    }
}

可能的话

function onPlayerStateChange(event,element) {
    //When the video has ended
    if (event.data == YT.PlayerState.ENDED) {
        //Get rid of the player
        element.style.display = "none";
    }
}




相关问题
mysql - store embed codes (youtube, vimeo etc)

How best to store the html for embedding? the only ways I can think of are: take the embed html and add <?php echo $var1; ?> where the id s go then store it in the db and use Eval to execute ...

openURL and YouTube

Is there any way to open the YouTube app from my app, with a defined search query? If not, is there a way to just open YouTube, without playing any video? All I m finding is ways to play videos.

emulating iPhone video player behaviour

I need to debug a networking application which handles video downloaded by iPhone from Youtube. iPhone downloads chunks of video by requesting each time a different file range (by adding Content-Range ...

Uploading video using the YouTube API via Flash AS3

I m trying to work out how to upload videos to YouTube using the api from flash. There seems to be libraries available for doing this with php, ruby, java etc. but not AS3. Can anyone point me in the ...

Curl setting Content-Type incorrectly

I am running a curl operation on the command line and am having trouble forcing the header to set as XML. I use the -H option to force the Content-Type to be xml, however, once I run the command I can ...

热门标签