YouTube Upload Widget/OnStateChange事件侦听器



我正试图使用YouTube上传小部件的onStateChange事件侦听器来根据上传小部件状态调用另一个函数,但我似乎无法让onStateChange活动侦听器与上传小部件一起工作。请参阅下面的代码。奇怪的是,当我使用相同的技术为iframe播放器单独添加onStateChange侦听器时,它运行得很好。有人有什么好主意吗?还是上传小部件api有问题?

<script>    
var player;
var widget;
function onYouTubeIframeAPIReady() {
player1 = new YT.Player('player1', {
    events: {
      }
                       }
                       );
 widget = new YT.UploadWidget('widget', {
      events: {
        'onStateChange': onWidgetStateChange,
        'onUploadSuccess': onUploadSuccess,
        'onProcessingComplete': onProcessingComplete
      }
    });
  }
function onWidgetStateChange(event) {
    if (event.data == YT.UploadWidgetState.RECORDING) {
      player1.playVideo();
              }
}
function onUploadSuccess(event) {
    alert('Video ID ' + event.data.videoId + ' was uploaded and is currently being       processed.');
  }
function onProcessingComplete(event) {
    player = new YT.Player('player', {
      height: 390,
      width: 640,
      videoId: event.data.videoId,
      events: {
          }
    });
  }

我认为您的问题是需要将event.data == YT.UploadWidgetState.RECORDING更改为event.data.state == YT.UploadWidgetState.RECORDING

在做出这一改变时,我能够制作出一个jsfiddle,它几乎可以满足您的需求:http://jsfiddle.net/jeffposnick/yhWsG/35/

相关内容

  • 没有找到相关文章

最新更新