Skip to content

Commit 287ec5a

Browse files
committed
fix: update demo site logic
1 parent 3ddc701 commit 287ec5a

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

demo/src/js/demo.js

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const commonConfig = {
2929
iosNative: true,
3030
},
3131
playsinline: true,
32+
vimeo: {
33+
// Prevent Vimeo blocking plyr.io demo site
34+
referrerPolicy: 'no-referrer',
35+
},
3236
};
3337

3438
(() => {
@@ -77,44 +81,22 @@ const commonConfig = {
7781
// Expose for tinkering in the console
7882
window.player = player;
7983

80-
/* The audio player needs the container element shown/hidden
81-
* The video player needs the media element shown/hidden
82-
* */
83-
function showHlsPlayer() {
84-
if (window.player.elements && window.player.elements.container) {
85-
window.player.elements.container.hidden = true;
86-
if (window.player.media) {
87-
window.player.media.hidden = true;
88-
window.player.pause();
89-
}
90-
}
91-
if (window.playerHls.elements && window.playerHls.elements.container) {
92-
window.playerHls.elements.container.hidden = false;
93-
if (window.playerHls.media) {
94-
window.playerHls.media.hidden = false;
84+
function togglePlayerVisibility(player, show) {
85+
if (player?.elements?.container) {
86+
player.elements.container.hidden = !show;
87+
if (player.media) {
88+
player.media.hidden = !show;
89+
if (!show) player.pause();
9590
}
9691
}
9792
}
98-
99-
/* The audio player needs the container element shown/hidden
100-
* The video player needs the media element shown/hidden
101-
* */
93+
function showHlsPlayer() {
94+
togglePlayerVisibility(window.player, false);
95+
togglePlayerVisibility(window.playerHls, true);
96+
}
10297
function showMainPlayer() {
103-
if (window.player.elements && window.player.elements.container) {
104-
window.player.elements.container.hidden = false;
105-
window.player.hidden = false;
106-
if (window.player.media) {
107-
window.player.media.hidden = false;
108-
window.player.media.pause();
109-
}
110-
}
111-
if (window.playerHls.elements && window.playerHls.elements.container) {
112-
window.playerHls.elements.container.hidden = true;
113-
window.playerHls.hidden = true;
114-
if (window.playerHls.media) {
115-
window.playerHls.media.hidden = true;
116-
}
117-
}
98+
togglePlayerVisibility(window.player, true);
99+
togglePlayerVisibility(window.playerHls, false);
118100
}
119101

120102
function render(type) {
@@ -163,9 +145,7 @@ const commonConfig = {
163145
}
164146
}
165147
else {
166-
if (window.playerHls) {
167-
window.playerHls.destroy();
168-
}
148+
window.playerHls?.destroy();
169149
player.source = sourceConfig;
170150
}
171151
// Set the current type for next time

demo/src/js/sources.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ const sources = {
129129
provider: 'vimeo',
130130
},
131131
],
132-
vimeo: {
133-
// Prevent Vimeo blocking plyr.io demo site
134-
referrerPolicy: 'no-referrer',
135-
},
136132
},
137133
};
138134

0 commit comments

Comments
 (0)