-
Notifications
You must be signed in to change notification settings - Fork 0
/
在线音视频播放器.html
168 lines (160 loc) · 5.84 KB
/
在线音视频播放器.html
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
<!DOCTYPE html>
<html>
<head>
<title>在线音视频播放器</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
background-color: black; /* 设置背景颜色为黑色 */
color: white; /* 设置文本颜色为白色 */
}
#videoContainer {
width: 90%; /* 将播放界面宽度调整为90% */
max-width: 800px;
margin-bottom: 20px;
}
#controlContainer {
display: flex;
justify-content: space-around;
width: 100%;
max-width: 800px;
}
#speedControl,
#volumeControl {
width: 80px;
margin-right: 10px;
}
</style>
</head>
<body>
<div id="videoContainer">
<input type="file" id="mediaFile" accept=".mp4, .mp3, .mov, audio/*, video/*">
<video id="mediaPlayer" width="100%" controls></video>
</div>
<div id="controlContainer">
<div>
<label for="speedControl">速度:</label>
<select id="speedControl">
<option value="0.1">0.1x</option>
<option value="0.2">0.2x</option>
<option value="0.3">0.3x</option>
<option value="0.4">0.4x</option>
<option value="0.5">0.5x</option>
<option value="0.6">0.6x</option>
<option value="0.7">0.7x</option>
<option value="0.8">0.8x</option>
<option value="0.9">0.9x</option>
<option value="1" selected>1x</option>
<option value="1.25">1.25x</option>
<option value="1.5">1.5x</option>
<option value="1.75">1.75x</option>
<option value="2">2x</option>
<option value="2.25">2.25x</option>
<option value="2.5">2.5x</option>
<option value="2.75">2.75x</option>
<option value="3">3x</option>
<option value="3.25">3.25x</option>
<option value="3.5">3.5x</option>
<option value="3.75">3.75x</option>
<option value="4">4x</option>
<option value="4.25">4.25x</option>
<option value="4.5">4.5x</option>
<option value="4.75">4.75x</option>
<option value="5">5x</option>
<option value="5.25">5.25x</option>
<option value="5.5">5.5x</option>
<option value="5.75">5.75x</option>
<option value="6">6x</option>
<option value="6.25">6.25x</option>
<option value="6.5">6.5x</option>
<option value="6.75">6.75x</option>
<option value="7">7x</option>
<option value="7.25">7.25x</option>
<option value="7.5">7.5x</option>
<option value="7.75">7.75x</option>
<option value="8">8x</option>
<option value="8.25">8.25x</option>
<option value="8.5">8.5x</option>
<option value="8.75">8.75x</option>
<option value="9">9x</option>
<option value="9.25">9.25x</option>
<option value="9.5">9.5x</option>
<option value="9.75">9.75x</option>
<option value="10">10x</option>
<option value="10.25">10.25x</option>
<option value="10.5">10.5x</option>
<option value="10.75">10.75x</option>
<option value="11">11x</option>
<option value="11.25">11.25x</option>
<option value="11.5">11.5x</option>
<option value="11.75">11.75x</option>
<option value="12">12x</option>
<option value="12.25">12.25x</option>
<option value="12.5">12.5x</option>
<option value="12.75">12.75x</option>
<option value="13">13x</option>
<option value="13.25">13.25x</option>
<option value="13.5">13.5x</option>
<option value="13.75">13.75x</option>
<option value="14">14x</option>
<option value="14.25">14.25x</option>
<option value="14.5">14.5x</option>
<option value="14.75">14.75x</option>
<option value="15">15x</option>
<option value="15.25">15.25x</option>
<option value="15.5">15.5x</option>
<option value="15.75">15.75x</option>
<option value="16">16x</option>
</select>
</div>
<div>
<label for="volumeControl">音量:</label>
<input type="range" id="volumeControl" min="0" max="40" step="1" value="10">
</div>
<button id="loopButton">循环</button>
</div>
<script>
const mediaFileInput = document.getElementById('mediaFile');
const mediaPlayer = document.getElementById('mediaPlayer');
const speedControl = document.getElementById('speedControl');
const volumeControl = document.getElementById('volumeControl');
const loopButton = document.getElementById('loopButton');
mediaFileInput.addEventListener('change', function(event) {
const file = event.target.files[0];
const objectURL = URL.createObjectURL(file);
mediaPlayer.src = objectURL;
});
speedControl.addEventListener('change', function() {
const playbackRate = parseFloat(speedControl.value);
mediaPlayer.playbackRate = playbackRate;
});
volumeControl.addEventListener('input', function() {
const volumeLevel = parseInt(volumeControl.value) / 20;
mediaPlayer.volume = volumeLevel;
});
loopButton.addEventListener('click', function() {
if (mediaPlayer.loop) {
mediaPlayer.loop = false;
loopButton.innerText = '循环';
} else {
mediaPlayer.loop = true;
loopButton.innerText = '取消循环';
}
});
// 监听键盘事件
document.addEventListener('keydown', function(event) {
if (event.key === 'ArrowUp' && volumeControl.value < 20) {
volumeControl.value = parseInt(volumeControl.value) + 1;
} else if (event.key === 'ArrowDown' && volumeControl.value > 0) {
volumeControl.value = parseInt(volumeControl.value) - 1;
}
const volumeLevel = parseInt(volumeControl.value) / 20;
mediaPlayer.volume = volumeLevel;
});
</script>
</body>
</html>