File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change 26
26
}
27
27
28
28
// Playing the base64 sound
29
- artoo . beep = function ( sound ) {
30
- var chosenSound ;
29
+ artoo . beep = function ( a1 , a2 ) {
30
+ var sound ,
31
+ callback ,
32
+ chosenSound ;
33
+
34
+ if ( typeof a1 === 'function' ) {
35
+ callback = a1 ;
36
+ }
37
+ else {
38
+ sound = a1 ;
39
+ if ( typeof a2 === 'function' )
40
+ callback = a2 ;
41
+ else if ( typeof a2 !== 'undefined' )
42
+ throw Error ( 'artoo.beep: second argument have to be a function.' ) ;
43
+ }
44
+
31
45
if ( artoo . helpers . isArray ( sound ) )
32
46
chosenSound = randomInArray ( sound ) ;
33
47
else
39
53
if ( ! ~ sounds . indexOf ( chosenSound ) )
40
54
throw Error ( 'artoo.beep: wrong sound specified.' ) ;
41
55
42
- new Audio ( artoo . settings . beep . endpoint + chosenSound + '.ogg' ) . play ( ) ;
56
+ var player = new Audio ( artoo . settings . beep . endpoint + chosenSound + '.ogg' ) ;
57
+ if ( callback )
58
+ player . addEventListener ( 'ended' , function ( ) {
59
+ callback ( ) ;
60
+ } ) ;
61
+ player . play ( ) ;
43
62
} ;
44
63
45
64
// Exposing available beeps
You can’t perform that action at this time.
0 commit comments