0

我正在尝试使用 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: {

          }
    });
  }

4

1 回答 1

0

我相信您的问题是您需要更改event.data == YT.UploadWidgetState.RECORDINGevent.data.state == YT.UploadWidgetState.RECORDING

在进行更改时,我能够组合一个 jsfiddle,它几乎可以满足您的需求:http: //jsfiddle.net/jeffposnick/yhWsG/35/

于 2013-07-30T20:09:12.370 回答