-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhls.html
More file actions
128 lines (112 loc) · 4.36 KB
/
hls.html
File metadata and controls
128 lines (112 loc) · 4.36 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HLS Video Player</title>
<style>
body {
margin: 0;
overflow: hidden;
font-family: 'Arial', sans-serif;
}
#hlsPlayerContainer {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
}
#hlsPlayer {
width: 100%;
height: 100%;
object-fit: cover;
}
#skipButton {
position: absolute;
top: 10px;
right: 10px;
font-size: 16px;
padding: 8px 12px;
background-color: #3498db;
color: #ffffff;
border: none;
border-radius: 4px;
cursor: pointer;
opacity: 0;
transition: opacity 0.5s ease;
}
#skipButton.visible {
opacity: 1;
}
</style>
</head>
<body>
<div id="hlsPlayerContainer">
<video id="hlsPlayer" controls></video>
<button id="skipButton">Skip Intro</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
var videoPlayerContainer = document.getElementById('hlsPlayerContainer');
var videoPlayer = document.getElementById('hlsPlayer');
var skipButton = document.getElementById('skipButton');
videoPlayer.src = 'video/Master.m3u8';
var hls = new Hls();
hls.loadSource('video/Master.m3u8');
hls.attachMedia(videoPlayer);
// Aggiungi un gestore per l'evento 'timeupdate' del video
videoPlayer.addEventListener('timeupdate', function () {
// Mostra il pulsante "Skip" dopo 5 secondi
if (videoPlayer.currentTime > 5) {
skipButton.classList.add('visible');
}
});
skipButton.addEventListener('click', function () {
var skipTime = 30;
if (!isNaN(videoPlayer.duration)) {
var newPosition = videoPlayer.currentTime + skipTime;
videoPlayer.currentTime = newPosition;
// Nascondi il pulsante "Skip" senza animazione
skipButton.style.display = 'none';
}
});
// Aggiungi un gestore per l'evento 'click' sul video per attivare il modo a schermo intero
videoPlayerContainer.addEventListener('click', function () {
if (document.fullscreenElement) {
// Se siamo già in modalità schermo intero, usciamo
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
} else {
// Se non siamo in modalità schermo intero, entriamo
if (videoPlayerContainer.requestFullscreen) {
videoPlayerContainer.requestFullscreen();
} else if (videoPlayerContainer.mozRequestFullScreen) {
videoPlayerContainer.mozRequestFullScreen();
} else if (videoPlayerContainer.webkitRequestFullscreen) {
videoPlayerContainer.webkitRequestFullscreen();
} else if (videoPlayerContainer.msRequestFullscreen) {
videoPlayerContainer.msRequestFullscreen();
}
}
});
// Aggiungi un gestore per l'evento 'fullscreenchange'
document.addEventListener('fullscreenchange', function () {
// Mostra il pulsante "Skip" solo quando il video è in modalità schermo intero
if (document.fullscreenElement === videoPlayerContainer && document.hasFocus()) {
skipButton.style.display = 'block';
} else {
skipButton.style.display = 'none';
}
});
});
</script>
</body>
</html>