我懒加载 Wistia 视频,单击图像后它们被注入到 DOM 中。我正在尝试获取视频句柄,以便在新视频开始播放时暂停视频,但 Wistia API 回调未触发。
function getAllVideos() {
window._wq = window._wq || [];
console.log(window._wq)
window._wq.push({
id: "_all",
onEmbedded: function(video) {
console.log('inside ready');
}
})
console.log(window._wq)
}
我总是收到一个空数组。Wistia.api.all()
还返回一个空数组。可能是因为异步?我通过像这样调用 Wistia api 来注入 iframe:
$slide.getJSON('http://fast.wistia.com/oembed/?url=http://home.wistia.com/medias/' + embed + '&format=json')
.then(res => {
var thumbnail = new Image(); // create image to hold thumbnail
thumbnail.src = res.thumbnail_url; // set thumbnail source
var videoContainer = document.getElementById('slick-slide0' + i); // each slide get video container
videoContainer.appendChild(thumbnail);
videoContainer.innerHTML += '<div class="play-button"></div>';
var slider = document.getElementById('slick-slide-control0' + i);
// on click of each image, create iframe, remove image, insert iframe
videoContainer.addEventListener('click', function() {
var iframeEmbed = document.getElementById('{{parent_custom_widget_name}}_' + i).innerHTML;
var iframe = document.createElement('iframe');
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('allowfullscreen', 'true');
iframe.setAttribute('src', '//fast.wistia.net/embed/iframe/' + iframeEmbed + '?autoplay=true');
this.innerHTML = '';
this.appendChild(iframe);
getAllVideos();
});
});