Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
ableplayer/scripts/volume.js at develop · ableplayer/ableplayer · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ableplayer
ableplayer
Repository navigation
Code
Issues
88
(88)
Pull requests
Actions
Projects
Wiki
Security and quality
1
(1)
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
ableplayer
/
scripts
/
volume.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
280 lines (231 loc) · 7.72 KB
develop
Breadcrumbs
ableplayer
/
scripts
/
volume.js
Copy path
Top
File metadata and controls
Code
Blame
280 lines (231 loc) · 7.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
$
from
'jquery'
;
function
addVolumeFunctions
(
AblePlayer
)
{
AblePlayer
.
prototype
.
addVolumeSlider
=
function
(
$div
)
{
// Prior to v4.4.64, we were using a custom-build vertical volunme slider
// Changed to input type="range" because it's standard and gaining more widespread support
// including screen reader support
// TODO: Improve presentation of vertical slider. That requires some CSS finesse.
var
thisObj
,
volumeSliderId
,
volumeHelpId
,
volumePct
,
volumeLabel
,
volumeHeight
;
thisObj
=
this
;
// define a few variables
volumeSliderId
=
this
.
mediaId
+
'-volume-slider'
;
volumeHelpId
=
this
.
mediaId
+
'-volume-help'
;
this
.
$volumeSlider
=
$
(
'<div>'
,
{
'id'
:
volumeSliderId
,
'class'
:
'able-volume-slider'
,
'aria-hidden'
:
'true'
}
)
.
hide
(
)
;
this
.
$volumeSliderTooltip
=
$
(
'<div>'
,
{
'class'
:
'able-tooltip'
,
'role'
:
'tooltip'
}
)
.
hide
(
)
;
this
.
$volumeRange
=
$
(
'<input>'
,
{
'type'
:
'range'
,
'min'
:
'0'
,
'max'
:
'10'
,
'step'
:
'1'
,
'orient'
:
'vertical'
,
// non-standard, but required for Firefox
'aria-label'
:
this
.
translate
(
'volumeUpDown'
,
'Volume up down'
)
,
'value'
:
this
.
volume
}
)
;
volumePct
=
parseInt
(
thisObj
.
volume
)
/
10
*
100
;
this
.
$volumeHelp
=
$
(
'<div>'
,
{
'id'
:
volumeHelpId
,
'class'
:
'able-volume-help'
,
'aria-live'
:
'polite'
}
)
.
text
(
volumePct
+
'%'
)
;
volumeLabel
=
this
.
$volumeButton
.
attr
(
'aria-label'
)
;
this
.
$volumeButton
.
attr
(
'aria-label'
,
volumeLabel
+
' '
+
volumePct
+
'%'
)
;
this
.
$volumeSlider
.
append
(
this
.
$volumeSliderTooltip
,
this
.
$volumeRange
,
this
.
$volumeHelp
)
;
volumeHeight
=
this
.
$volumeButton
.
parents
(
'.able-control-row'
)
[
0
]
;
this
.
$volumeSlider
.
css
(
'bottom'
,
volumeHeight
.
offsetHeight
)
;
$div
.
append
(
this
.
$volumeSlider
)
;
// add event listeners
this
.
$volumeRange
.
on
(
'change'
,
function
(
e
)
{
thisObj
.
handleVolumeChange
(
$
(
this
)
.
val
(
)
)
;
}
)
;
this
.
$volumeRange
.
on
(
'input'
,
function
(
e
)
{
thisObj
.
handleVolumeChange
(
$
(
this
)
.
val
(
)
)
;
}
)
;
this
.
$volumeRange
.
on
(
'keydown'
,
function
(
e
)
{
if
(
e
.
key
===
'Escape'
||
e
.
key
===
'Tab'
||
e
.
key
===
'Enter'
)
{
// close popup
if
(
thisObj
.
$volumeSlider
.
is
(
':visible'
)
)
{
thisObj
.
closingVolume
=
true
;
// stopgap
thisObj
.
hideVolumePopup
(
)
;
}
else
{
if
(
!
thisObj
.
closingVolume
)
{
thisObj
.
showVolumePopup
(
)
;
}
}
}
else
{
return
;
}
}
)
;
}
;
AblePlayer
.
prototype
.
refreshVolumeHelp
=
function
(
volume
)
{
// make adjustments based on current volume
var
volumePct
;
volumePct
=
(
volume
/
10
)
*
100
;
// Update help text
if
(
this
.
$volumeHelp
)
{
this
.
$volumeHelp
.
text
(
volumePct
+
'%'
)
;
}
// Update the default value of the volume slider input field
// This doesn't seem to be necessary; browsers remember the previous setting during a session
// but this is a fallback in case they don't
this
.
$volumeRange
.
attr
(
'value'
,
volume
)
;
}
;
AblePlayer
.
prototype
.
refreshVolumeButton
=
function
(
volume
)
{
var
volumeName
,
volumePct
,
volumeLabel
;
volumeName
=
this
.
getVolumeName
(
volume
)
;
volumePct
=
(
volume
/
10
)
*
100
;
volumeLabel
=
this
.
translate
(
'volume'
,
'Volume'
)
+
' '
+
volumePct
+
'%'
;
this
.
getIcon
(
this
.
$volumeButton
,
'volume-'
+
volumeName
)
;
this
.
$volumeButton
.
attr
(
'aria-label'
,
volumeLabel
)
;
}
;
AblePlayer
.
prototype
.
handleVolumeButtonClick
=
function
(
)
{
if
(
this
.
$volumeSlider
.
is
(
':visible'
)
)
{
this
.
hideVolumePopup
(
)
;
}
else
{
this
.
showVolumePopup
(
)
;
}
}
;
AblePlayer
.
prototype
.
handleVolumeKeystroke
=
function
(
volume
)
{
// keyboard shortcuts for changing volume
if
(
this
.
isMuted
(
)
&&
volume
>
0
)
{
this
.
setMute
(
false
)
;
}
else
if
(
volume
===
0
)
{
this
.
setMute
(
true
)
;
}
else
{
this
.
setVolume
(
volume
)
;
// this.volume will be updated after volumechange event fires (event.js)
this
.
refreshVolumeHelp
(
volume
)
;
this
.
refreshVolumeButton
(
volume
)
;
}
}
;
AblePlayer
.
prototype
.
handleVolumeChange
=
function
(
volume
)
{
// handle volume change using the volume input slider
if
(
this
.
isMuted
(
)
&&
volume
>
0
)
{
this
.
setMute
(
false
)
;
}
else
if
(
volume
===
0
)
{
this
.
setMute
(
true
)
;
}
else
{
this
.
setVolume
(
volume
)
;
// this.volume will be updated after volumechange event fires (event.js)
this
.
refreshVolumeHelp
(
volume
)
;
this
.
refreshVolumeButton
(
volume
)
;
}
}
;
AblePlayer
.
prototype
.
handleMute
=
function
(
)
{
if
(
this
.
isMuted
(
)
)
{
this
.
setMute
(
false
)
;
}
else
{
this
.
setMute
(
true
)
;
}
}
;
AblePlayer
.
prototype
.
showVolumePopup
=
function
(
)
{
this
.
closePopups
(
)
;
this
.
$tooltipDiv
.
hide
(
)
;
this
.
$volumeSlider
.
show
(
)
.
attr
(
'aria-hidden'
,
'false'
)
;
this
.
$volumeButton
.
attr
(
'aria-expanded'
,
'true'
)
;
this
.
$volumeButton
.
focus
(
)
;
// for screen reader expanded state to be read
this
.
waitThenFocus
(
this
.
$volumeRange
)
;
}
;
AblePlayer
.
prototype
.
hideVolumePopup
=
function
(
)
{
var
thisObj
=
this
;
this
.
$volumeSlider
.
hide
(
)
.
attr
(
'aria-hidden'
,
'true'
)
;
this
.
$volumeButton
.
attr
(
'aria-expanded'
,
'false'
)
.
focus
(
)
;
// wait a second before resetting stopgap var
// otherwise the keypress used to close volume popup will trigger the volume button
setTimeout
(
function
(
)
{
thisObj
.
closingVolume
=
false
;
}
,
1000
)
;
}
;
AblePlayer
.
prototype
.
isMuted
=
function
(
)
{
if
(
this
.
player
===
'html5'
)
{
return
this
.
media
.
muted
;
}
else
if
(
this
.
player
===
'youtube'
)
{
return
this
.
youTubePlayer
.
isMuted
(
)
;
}
}
;
AblePlayer
.
prototype
.
setMute
=
function
(
mute
)
{
// mute is either true (muting) or false (unmuting)
if
(
mute
)
{
// save current volume so it can be restored after unmute
this
.
lastVolume
=
(
this
.
volume
===
0
)
?
this
.
defaultVolume
:
this
.
volume
;
this
.
volume
=
0
;
}
else
{
// restore to previous volume
if
(
typeof
this
.
lastVolume
!==
'undefined'
)
{
this
.
volume
=
this
.
lastVolume
===
0
?
this
.
defaultVolume
:
this
.
lastVolume
;
}
else
{
this
.
volume
=
this
.
defaultVolume
;
}
}
if
(
this
.
player
===
'html5'
)
{
this
.
media
.
muted
=
mute
;
}
else
if
(
this
.
player
===
'youtube'
)
{
if
(
mute
)
{
this
.
youTubePlayer
.
mute
(
)
;
}
else
{
this
.
youTubePlayer
.
unMute
(
)
;
}
}
this
.
setVolume
(
this
.
volume
)
;
this
.
refreshVolumeHelp
(
this
.
volume
)
;
this
.
refreshVolumeButton
(
this
.
volume
)
;
}
;
AblePlayer
.
prototype
.
setVolume
=
function
(
volume
)
{
// volume is 1 to 10
// convert as needed depending on player
var
newVolume
;
this
.
syncSignVideo
(
{
'volume'
:
0
}
)
;
if
(
this
.
player
===
'html5'
)
{
// volume is 0 to 1
newVolume
=
volume
/
10
;
this
.
media
.
volume
=
newVolume
;
}
else
if
(
this
.
player
===
'youtube'
)
{
// volume is 0 to 100
newVolume
=
volume
*
10
;
this
.
youTubePlayer
.
setVolume
(
newVolume
)
;
this
.
volume
=
volume
;
}
else
if
(
this
.
player
===
'vimeo'
)
{
// volume is 0 to 1
newVolume
=
volume
/
10
;
this
.
vimeoPlayer
.
setVolume
(
newVolume
)
.
then
(
function
(
)
{
// setVolume finished.
// successful completion also fires a 'volumechange' event (see event.js)
}
)
;
}
this
.
lastVolume
=
volume
;
}
;
AblePlayer
.
prototype
.
getVolume
=
function
(
volume
)
{
// return volume using common audio control scale 1 to 10
if
(
this
.
player
===
'html5'
)
{
// uses 0 to 1 scale
return
this
.
media
.
volume
*
10
;
}
else
if
(
this
.
player
===
'youtube'
)
{
// uses 0 to 100 scale
if
(
this
.
youTubePlayerReady
)
{
return
this
.
youTubePlayer
.
getVolume
(
)
/
10
;
}
}
if
(
this
.
player
===
'vimeo'
)
{
// uses 0 to 1 scale
// this.vimeoPlayer.getVolume() takes too long to resolve with a value
// Just use variable that's already been defined (should be the same value anyway)
return
this
.
volume
;
}
}
;
AblePlayer
.
prototype
.
getVolumeName
=
function
(
volume
)
{
// returns 'mute','soft','medium', or 'loud' depending on volume level
if
(
volume
==
0
)
{
return
'mute'
;
}
else
if
(
volume
==
10
)
{
return
'loud'
;
}
else
if
(
volume
<
5
)
{
return
'soft'
;
}
else
{
return
'medium'
;
}
}
;
}
export
default
addVolumeFunctions
;
You can’t perform that action at this time.