Repository navigation
Expand file tree
/
Copy pathnetflix-player.html
More file actions
339 lines (292 loc) · 10.1 KB
/
Copy pathnetflix-player.html
File metadata and controls
339 lines (292 loc) · 10.1 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Netflix Streaming Demo</title>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #141414;
font-family: 'Arial', sans-serif;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 20px;
}
.logo {
color: #E50914;
font-size: 48px;
font-weight: bold;
letter-spacing: 3px;
margin-bottom: 10px;
}
.subtitle {
color: #999;
font-size: 14px;
margin-bottom: 40px;
letter-spacing: 1px;
}
.search-container {
display: flex;
gap: 10px;
margin-bottom: 20px;
width: 100%;
max-width: 700px;
}
input {
flex: 1;
padding: 14px 18px;
font-size: 16px;
border-radius: 5px;
border: 2px solid #333;
background: #222;
color: #fff;
outline: none;
transition: border-color 0.3s;
}
input:focus {
border-color: #E50914;
}
input::placeholder {
color: #666;
}
button {
padding: 14px 28px;
background: #E50914;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
font-weight: bold;
cursor: pointer;
transition: background 0.2s;
white-space: nowrap;
}
button:hover {
background: #f40612;
}
button:disabled {
background: #666;
cursor: not-allowed;
}
#status {
font-size: 14px;
margin-bottom: 20px;
height: 20px;
text-align: center;
}
.status-loading {
color: #fff;
}
.status-success {
color: #46d369;
}
.status-error {
color: #E50914;
}
.video-container {
width: 100%;
max-width: 900px;
background: #000;
border-radius: 8px;
overflow: hidden;
border: 2px solid #333;
}
video {
width: 100%;
display: block;
min-height: 400px;
background: #000;
}
.info-box {
margin-top: 20px;
background: #222;
border-radius: 8px;
padding: 20px;
width: 100%;
max-width: 900px;
display: none;
}
.info-box h3 {
color: #E50914;
margin-bottom: 15px;
font-size: 16px;
}
.info-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 12px;
}
.info-item {
background: #333;
padding: 12px;
border-radius: 5px;
}
.info-label {
color: #999;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 4px;
}
.info-value {
color: #fff;
font-size: 14px;
word-break: break-all;
}
.tech-stack {
margin-top: 30px;
color: #666;
font-size: 12px;
text-align: center;
}
.tech-stack span {
color: #E50914;
font-weight: bold;
}
</style>
</head>
<body>
<div class="logo">NETFLIX</div>
<div class="subtitle">Streaming Platform Demo — Spring Boot + Kafka + AWS S3 + Redis</div>
<div class="search-container">
<input type="text" id="movieId" placeholder="Enter Movie ID (from Content Service)"
onkeypress="if(event.key==='Enter') loadMovie()" />
<button id="playBtn" onclick="loadMovie()">▶ Play</button>
</div>
<div id="status"></div>
<div class="video-container">
<video id="video" controls></video>
</div>
<div class="info-box" id="infoBox">
<h3>📊 Stream Information</h3>
<div class="info-grid">
<div class="info-item">
<div class="info-label">Movie ID</div>
<div class="info-value" id="infoMovieId">—</div>
</div>
<div class="info-item">
<div class="info-label">Available Qualities</div>
<div class="info-value" id="infoQuality">—</div>
</div>
<div class="info-item">
<div class="info-label">URL Expires In</div>
<div class="info-value" id="infoExpiry">—</div>
</div>
<div class="info-item">
<div class="info-label">Streaming URL</div>
<div class="info-value" id="infoUrl">—</div>
</div>
</div>
</div>
<div class="tech-stack">
Built with <span>Spring Boot</span> · <span>Apache Kafka</span> ·
<span>AWS S3</span> · <span>Redis</span> · <span>FFmpeg HLS</span>
</div>
<script>
var hlsInstance = null;
function setStatus(message, type) {
var status = document.getElementById('status');
status.textContent = message;
status.className = 'status-' + type;
}
function loadMovie() {
var movieId = document.getElementById('movieId').value.trim();
var playBtn = document.getElementById('playBtn');
if (!movieId) {
setStatus('❌ Please enter a Movie ID', 'error');
return;
}
// Disable button while loading
playBtn.disabled = true;
playBtn.textContent = '⏳ Loading...';
setStatus('⏳ Fetching stream from Streaming Service...', 'loading');
// Call Streaming Service
fetch('http://localhost:8084/api/v1/stream/' + encodeURIComponent(movieId))
.then(function (response) {
if (!response.ok) {
throw new Error('Movie not found or not ready for streaming');
}
return response.json();
})
.then(function (data) {
if (!data.streamingURL) {
throw new Error('Streaming service did not return a playlist URL');
}
setStatus('✅ Stream loaded! Playing in ' + data.quality, 'success');
updateInfoBox(data);
playHLS(data.streamingURL, movieId);
playBtn.disabled = false;
playBtn.textContent = '▶ Play';
})
.catch(function (error) {
setStatus('❌ ' + error.message, 'error');
playBtn.disabled = false;
playBtn.textContent = '▶ Play';
});
}
function playHLS(streamUrl, movieId) {
var video = document.getElementById('video');
if (hlsInstance) {
hlsInstance.destroy();
hlsInstance = null;
}
if (Hls.isSupported()) {
hlsInstance = new Hls({
// Override URL loader to route through our signing endpoint
xhrSetup: function (xhr, url) {
// If this is an m3u8 request — route through our signing endpoint
if (url.includes('.m3u8') && !url.includes('X-Amz')) {
var playlistPath = new URL(url).pathname.substring(1);
var encodedPath = encodeURIComponent(playlistPath);
xhr.open('GET',
'http://localhost:8084/api/v1/stream/' +
encodeURIComponent(movieId) + '/playlist?path=' + encodedPath
);
}
}
});
hlsInstance.loadSource(streamUrl);
hlsInstance.attachMedia(video);
hlsInstance.on(Hls.Events.MANIFEST_PARSED, function () {
video.play().catch(function () {
setStatus('✅ Stream ready. Press Play to start video.', 'success');
});
});
hlsInstance.on(Hls.Events.ERROR, function (event, data) {
if (data.fatal) {
setStatus('❌ Unable to play this stream. Check the playlist, S3 CORS, and streaming service logs.', 'error');
hlsInstance.destroy();
hlsInstance = null;
}
});
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = streamUrl;
video.play().catch(function () {
setStatus('✅ Stream ready. Press Play to start video.', 'success');
});
} else {
setStatus('❌ This browser does not support HLS playback.', 'error');
}
}
function updateInfoBox(data) {
document.getElementById('infoBox').style.display = 'block';
document.getElementById('infoMovieId').textContent = data.movieId;
document.getElementById('infoQuality').textContent = data.quality;
document.getElementById('infoExpiry').textContent =
data.expiredInMinutes + ' minutes';
document.getElementById('infoUrl').textContent =
data.streamingURL.length > 60
? data.streamingURL.substring(0, 60) + '...'
: data.streamingURL;
}
</script>
</body>
</html>