-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
186 lines (157 loc) · 5.65 KB
/
example.html
File metadata and controls
186 lines (157 loc) · 5.65 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Volume Control Component Demo</title>
<link rel="stylesheet" href="volume-control.css">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
}
.demo-section {
background: white;
padding: 20px;
margin: 20px 0;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1, h2 {
color: #333;
}
.code-block {
background: #f8f9fa;
padding: 15px;
border-radius: 4px;
overflow-x: auto;
margin: 15px 0;
}
.audio-demo {
display: flex;
flex-direction: column;
gap: 20px;
}
.test-controls {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
button {
padding: 8px 16px;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #0056b3;
}
.log-output {
background: #000;
color: #00ff00;
padding: 15px;
border-radius: 4px;
font-family: monospace;
height: 200px;
overflow-y: auto;
}
</style>
</head>
<body>
<h1>Volume Control Component Demo</h1>
<div class="demo-section">
<h2>Vanilla JavaScript Usage</h2>
<div id="volume-control-container"></div>
<div class="code-block">
<pre><code>// Basic usage
const volumeControl = new VolumeControl();
document.getElementById('container').appendChild(volumeControl.getElement());
// With callbacks
volumeControl.on('onVolumeChange', (volume, muted) => {
console.log('Volume changed:', volume, muted);
});
volumeControl.on('onMuteToggle', (volume, muted) => {
console.log('Mute toggled:', muted);
});
// Connect to audio element
const audio = new Audio('audio.mp3');
volumeControl.connectAudioElement(audio);</code></pre>
</div>
</div>
<div class="demo-section">
<h2>HTML5 Audio Element Integration</h2>
<div class="audio-demo">
<audio id="demo-audio" controls>
<source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div id="audio-volume-control"></div>
<div class="test-controls">
<button onclick="testVolume(0)">Set Volume 0%</button>
<button onclick="testVolume(50)">Set Volume 50%</button>
<button onclick="testVolume(100)">Set Volume 100%</button>
<button onclick="testMute()">Toggle Mute</button>
</div>
</div>
</div>
<div class="demo-section">
<h2>Event Log</h2>
<div id="event-log" class="log-output"></div>
</div>
<div class="demo-section">
<h2>Keyboard Controls</h2>
<p>Focus the volume slider and use:</p>
<ul>
<li>←/→ or ↑/↓ arrows to adjust volume</li>
<li>M key to toggle mute</li>
<li>Enter/Space on mute button to toggle</li>
</ul>
</div>
<script src="volume-control.js"></script>
<script>
// Initialize volume controls
const volumeControl = new VolumeControl();
document.getElementById('volume-control-container').appendChild(volumeControl.getElement());
// Initialize audio volume control
const audio = document.getElementById('demo-audio');
const audioVolumeControl = new VolumeControl({ defaultValue: 80 });
document.getElementById('audio-volume-control').appendChild(audioVolumeControl.getElement());
audioVolumeControl.connectAudioElement(audio);
// Event logging
function logEvent(message) {
const log = document.getElementById('event-log');
log.innerHTML += `${new Date().toLocaleTimeString()}: ${message}\n`;
log.scrollTop = log.scrollHeight;
}
// Setup event listeners
volumeControl.on('onVolumeChange', (volume, muted) => {
logEvent(`Volume changed: ${volume}% ${muted ? '(muted)' : ''}`);
});
volumeControl.on('onMuteToggle', (volume, muted) => {
logEvent(`Mute ${muted ? 'enabled' : 'disabled'} at ${volume}%`);
});
audioVolumeControl.on('onVolumeChange', (volume, muted) => {
logEvent(`Audio volume: ${volume}% ${muted ? '(muted)' : ''}`);
});
// Test functions
function testVolume(level) {
audioVolumeControl.setVolume(level);
logEvent(`Programmatically set volume to ${level}%`);
}
function testMute() {
audioVolumeControl.toggleMute();
logEvent('Programmatically toggled mute');
}
// Demo localStorage persistence
setTimeout(() => {
const savedVolume = audioVolumeControl.loadVolume();
logEvent(`Loaded saved volume from localStorage: ${savedVolume}%`);
}, 1000);
</script>
</body>
</html>