$(document).ready (function() {
console.log('onYouTubeIframeAPIReady');
let containers = {}, players = {};
@foreach($trade_videos as $video)
containers['{{$video->youtube}}'] = document.querySelector('#player-container-{{$video->youtube}}');
players['{{$video->youtube}}'] = document.querySelector('#player-{{$video->youtube}}');
players['{{$video->youtube}}'] = new YKU.Player( 'player-{{$video->youtube}}', {
height: containers['{{$video->youtube}}'].children[0].offsetHeight,
width: containers['{{$video->youtube}}'].children[0].offsetWidth,
// playerVars: {enablejsapi: 1, rel: 0, modestbranding: 1, autohide: 1},
styleid: '0',
autoplay: false,
vid: '{{$video->youtube}}',
client_id: 'CLIENT_ID',
newPlayer: true,
{{--events: {--}}
{{--onPlayerReady: function (e) {--}}
{{--e.target.a.parentNode.classList.add('playable');--}}
{{--},--}}
{{--onPlayStart: function(){--}}
{{--containers['{{$video->youtube}}'].classList.add('playing');--}}
{{--},--}}
{{--onPlayEnd: function(){--}}
{{--containers['{{$video->youtube}}'].classList.remove('playing');--}}
{{--}--}}
{{--}--}}
});
containers['{{$video->youtube}}'].addEventListener('click',function(){ players['{{$video->youtube}}'].playVideo(); });
@endforeach
});
我不确定我是否遗漏了优酷 api 的某些内容,同样的设置适用于 youtube,但优酷返回Uncaught TypeError: Cannot read property 'pauseVideo' of null
的实际视频加载正常,似乎播放方法不起作用?有没有人遇到过类似的情况。