-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.html
More file actions
184 lines (166 loc) · 4.85 KB
/
player.html
File metadata and controls
184 lines (166 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flake Anime Internal Player</title>
<link rel="stylesheet" href="https://cdn.plyr.io/3.5.6/plyr.css">
<style>
body {
height: 100vh;
margin: 0px;
padding: 0px;
overflow: hidden;
}
video {
/* width: 100%;
height: 100%; */
margin: 0px 0px -10px 0px;
/* display: none; */
}
.loading {
display: flex;
transition: opacity .3s ease-in;
}
.circle {
background-color: #ED64A6;
border-radius: 50%;
margin: 2px;
height: 10px;
width: 10px;
animation: jump .5s ease-in infinite;
}
.circle:nth-of-type(2) {
animation-delay: 0.1s;
}
.circle:nth-of-type(3) {
animation-delay: 0.2s;
}
@keyframes jump {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-10px);
}
}
.loader {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
gap: 1rem;
}
.plyr--full-ui input[type=range] {
color: #ED64A6;
}
.plyr__control--overlaid {
background: rgba(237, 100, 166, .8);
}
.plyr--video .plyr__control.plyr__tab-focus,
.plyr--video .plyr__control:hover,
.plyr--video .plyr__control[aria-expanded=true] {
background: #ED64A6;
}
.plyr__control.plyr__tab-focus {
box-shadow: 0 0 0 5px rgba(237, 100, 166, .5);
}
.plyr__menu__container .plyr__control[role=menuitemradio][aria-checked=true]::before {
background: #ED64A6;
}
.container {
display: none;
}
.plyr {
height: 100vh; min-height: 100%;
}
</style>
</head>
<body>
<div class="loader">
<div class="loading">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
</div>
<div class="container">
<video playsinline crossorigin controls></video>
</div>
<script src="https://cdn.jsdelivr.net/npm/hls.js"></script>
<script src="https://unpkg.com/plyr@3"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
const url = new URL(window.location)
const playerLink = encodeURIComponent(url.searchParams.get('player_link'))
const video = document.querySelector("video");
const container = document.querySelector(".container");
const loader = document.querySelector(".loader");
function hideLoader() {
loader.style.display = "none";
}
function showPlayer() {
container.style.display = "block"
}
function updateQuality(newQuality) {
window.hls.levels.forEach((level, levelIndex) => {
if (level.height === newQuality) {
console.log("Found quality match with " + newQuality);
window.hls.currentLevel = levelIndex;
}
});
}
async function main() {
const defaultOptions = {};
const sources = await $.get(`/get_streaming_source?player_link=${playerLink}`)
const hlsSources = []
const mp4Sources = []
sources.forEach(source => {
if (source.type === 'application/x-mpegURL')
hlsSources.push(source)
else if (source.type === 'video/mp4')
mp4Sources.push(source)
});
if (hlsSources.length > 0) {
if (Hls.isSupported()) {
const source = hlsSources[0].url
const hls = new Hls();
hls.loadSource(source);
hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
const availableQualities = hls.levels.map((l) => l.height).reverse();
defaultOptions.quality = {
default: availableQualities[0],
options: availableQualities,
forced: true,
onChange: (e) => updateQuality(e),
}
const player = new Plyr(video, defaultOptions);
hideLoader();
showPlayer();
});
hls.attachMedia(video);
window.hls = hls;
} else {
console.log("hls is not supported by your browser");
const player = new Plyr(video, defaultOptions);
}
} else if (mp4Sources.length > 0) {
const player = new Plyr(video, defaultOptions);
player.source = {
type: 'video',
sources: mp4Sources
}
hideLoader();
showPlayer();
} else {
console.log("No sources found")
const player = new Plyr(video, defaultOptions);
hideLoader();
showPlayer();
}
}
document.addEventListener("DOMContentLoaded", main);
</script>
</body>
</html>