Более корректное воспроизведение видео при быстром пролистывании
This commit is contained in:
parent
4477563c66
commit
51abd182a2
45
index.js
45
index.js
|
@ -23,14 +23,18 @@ const playVideo = (slide) => {
|
||||||
|
|
||||||
if (youtube) {
|
if (youtube) {
|
||||||
if (slide.YTPlayer) {
|
if (slide.YTPlayer) {
|
||||||
slide.YTPlayer.playVideo();
|
if (slide.classList.contains('swiper-slide-active')) {
|
||||||
|
slide.YTPlayer.playVideo();
|
||||||
|
}
|
||||||
} else if (window.YT) {
|
} else if (window.YT) {
|
||||||
if (GalleryYTPlayer.state) {
|
if (GalleryYTPlayer.state) {
|
||||||
slide.YTPlayer = new YT.Player(youtube, {
|
slide.YTPlayer = new YT.Player(youtube, {
|
||||||
videoId: youtube.dataset.id,
|
videoId: youtube.dataset.id,
|
||||||
events: {
|
events: {
|
||||||
onReady(event) {
|
onReady(event) {
|
||||||
event.target.playVideo();
|
if (slide.classList.contains('swiper-slide-active')) {
|
||||||
|
event.target.playVideo();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -47,12 +51,16 @@ const playVideo = (slide) => {
|
||||||
}
|
}
|
||||||
} else if (vk) {
|
} else if (vk) {
|
||||||
if (slide.VKPlayer) {
|
if (slide.VKPlayer) {
|
||||||
slide.VKPlayer.play();
|
if (slide.classList.contains('swiper-slide-active')) {
|
||||||
|
slide.VKPlayer.play();
|
||||||
|
}
|
||||||
} else if (window.VK?.VideoPlayer) {
|
} else if (window.VK?.VideoPlayer) {
|
||||||
if (GalleryVKPlayer.state) {
|
if (GalleryVKPlayer.state) {
|
||||||
slide.VKPlayer = VK.VideoPlayer(vk);
|
slide.VKPlayer = VK.VideoPlayer(vk);
|
||||||
slide.VKPlayer.on('inited', () => {
|
slide.VKPlayer.on('inited', () => {
|
||||||
slide.VKPlayer.play();
|
if (slide.classList.contains('swiper-slide-active')) {
|
||||||
|
slide.VKPlayer.play();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
GalleryVKPlayer.addListener(() => {
|
GalleryVKPlayer.addListener(() => {
|
||||||
|
@ -71,13 +79,15 @@ const playVideo = (slide) => {
|
||||||
if (window.GalleryRTPlayer) {
|
if (window.GalleryRTPlayer) {
|
||||||
if (window.GalleryRTPlayer.has(videoId)) {
|
if (window.GalleryRTPlayer.has(videoId)) {
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
rt.contentWindow.postMessage(
|
if (slide.classList.contains('swiper-slide-active')) {
|
||||||
JSON.stringify({
|
rt.contentWindow.postMessage(
|
||||||
type: 'player:play',
|
JSON.stringify({
|
||||||
data: {},
|
type: 'player:play',
|
||||||
}),
|
data: {},
|
||||||
'*',
|
}),
|
||||||
);
|
'*',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
|
@ -338,11 +348,14 @@ const init = async (items = [], options = {}, index = 0) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
swiper.on('slideChange', function () {
|
swiper.on('slideChange', function () {
|
||||||
if (this.slides[this.previousIndex].classList.contains('advdominion-lg__item_video')) {
|
for (const [index, slide] of Object.entries(this.slides)) {
|
||||||
pauseVideo(this.slides[this.previousIndex]);
|
if (slide.classList.contains('advdominion-lg__item_video')) {
|
||||||
}
|
if (Number(index) === this.activeIndex) {
|
||||||
if (this.slides[this.activeIndex].classList.contains('advdominion-lg__item_video')) {
|
playVideo(slide);
|
||||||
playVideo(this.slides[this.activeIndex]);
|
} else {
|
||||||
|
pauseVideo(slide);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue