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