buzz-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in buzz-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Charles Lowell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Buzz::Rails
2
+
3
+ [buzz.js][1] is an HTML5 Audion library with an jQuery like API.
4
+
5
+ You might want to include it into your rails app.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'buzz-rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install buzz-rails
20
+
21
+ ## Usage
22
+
23
+ From within a sprocket manifest (like application.js)
24
+
25
+ //= require buzz
26
+
27
+ [1]: http://buzz.jaysalvat.com
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/buzz-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Charles Lowell"]
6
+ gem.email = ["cowboyd@thefrontside.net"]
7
+ gem.description = %q{use buzz.js in rails}
8
+ gem.summary = %q{Buzz is a jQuery like API for using HTML5 Audio}
9
+ gem.homepage = "http://buzz.jaysalvat.com"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "buzz-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Buzz::Rails::VERSION
17
+
18
+ gem.add_dependency 'rails', '~> 3.1'
19
+ end
data/lib/buzz-rails.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "buzz-rails/version"
2
+
3
+ module Buzz
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Buzz
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,855 @@
1
+ // ----------------------------------------------------------------------------
2
+ // Buzz, a Javascript HTML5 Audio library
3
+ // v 1.0.x beta
4
+ // Licensed under the MIT license.
5
+ // http://buzz.jaysalvat.com/
6
+ // ----------------------------------------------------------------------------
7
+ // Copyright (C) 2011 Jay Salvat
8
+ // http://jaysalvat.com/
9
+ // ----------------------------------------------------------------------------
10
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ // of this software and associated documentation files ( the "Software" ), to deal
12
+ // in the Software without restriction, including without limitation the rights
13
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ // copies of the Software, and to permit persons to whom the Software is
15
+ // furnished to do so, subject to the following conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be included in
18
+ // all copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ // THE SOFTWARE.
27
+ // ----------------------------------------------------------------------------
28
+
29
+ var buzz = {
30
+ defaults: {
31
+ autoplay: false,
32
+ duration: 5000,
33
+ formats: [],
34
+ loop: false,
35
+ placeholder: '--',
36
+ preload: 'metadata',
37
+ volume: 80
38
+ },
39
+ types: {
40
+ 'mp3': 'audio/mpeg',
41
+ 'ogg': 'audio/ogg',
42
+ 'wav': 'audio/wav',
43
+ 'aac': 'audio/aac',
44
+ 'm4a': 'audio/x-m4a'
45
+ },
46
+ sounds: [],
47
+ el: document.createElement( 'audio' ),
48
+
49
+ sound: function( src, options ) {
50
+ options = options || {};
51
+
52
+ var pid = 0,
53
+ events = [],
54
+ eventsOnce = {},
55
+ supported = buzz.isSupported();
56
+
57
+ // publics
58
+ this.load = function() {
59
+ if ( !supported ) {
60
+ return this;
61
+ }
62
+
63
+ this.sound.load();
64
+ return this;
65
+ };
66
+
67
+ this.play = function() {
68
+ if ( !supported ) {
69
+ return this;
70
+ }
71
+
72
+ this.sound.play();
73
+ return this;
74
+ };
75
+
76
+ this.togglePlay = function() {
77
+ if ( !supported ) {
78
+ return this;
79
+ }
80
+
81
+ if ( this.sound.paused ) {
82
+ this.sound.play();
83
+ } else {
84
+ this.sound.pause();
85
+ }
86
+ return this;
87
+ };
88
+
89
+ this.pause = function() {
90
+ if ( !supported ) {
91
+ return this;
92
+ }
93
+
94
+ this.sound.pause();
95
+ return this;
96
+ };
97
+
98
+ this.isPaused = function() {
99
+ if ( !supported ) {
100
+ return null;
101
+ }
102
+
103
+ return this.sound.paused;
104
+ };
105
+
106
+ this.stop = function() {
107
+ if ( !supported ) {
108
+ return this;
109
+ }
110
+
111
+ this.setTime( this.getDuration() );
112
+ this.sound.pause();
113
+ return this;
114
+ };
115
+
116
+ this.isEnded = function() {
117
+ if ( !supported ) {
118
+ return null;
119
+ }
120
+
121
+ return this.sound.ended;
122
+ };
123
+
124
+ this.loop = function() {
125
+ if ( !supported ) {
126
+ return this;
127
+ }
128
+
129
+ this.sound.loop = 'loop';
130
+ this.bind( 'ended.buzzloop', function() {
131
+ this.currentTime = 0;
132
+ this.play();
133
+ });
134
+ return this;
135
+ };
136
+
137
+ this.unloop = function() {
138
+ if ( !supported ) {
139
+ return this;
140
+ }
141
+
142
+ this.sound.removeAttribute( 'loop' );
143
+ this.unbind( 'ended.buzzloop' );
144
+ return this;
145
+ };
146
+
147
+ this.mute = function() {
148
+ if ( !supported ) {
149
+ return this;
150
+ }
151
+
152
+ this.sound.muted = true;
153
+ return this;
154
+ };
155
+
156
+ this.unmute = function() {
157
+ if ( !supported ) {
158
+ return this;
159
+ }
160
+
161
+ this.sound.muted = false;
162
+ return this;
163
+ };
164
+
165
+ this.toggleMute = function() {
166
+ if ( !supported ) {
167
+ return this;
168
+ }
169
+
170
+ this.sound.muted = !this.sound.muted;
171
+ return this;
172
+ };
173
+
174
+ this.isMuted = function() {
175
+ if ( !supported ) {
176
+ return null;
177
+ }
178
+
179
+ return this.sound.muted;
180
+ };
181
+
182
+ this.setVolume = function( volume ) {
183
+ if ( !supported ) {
184
+ return this;
185
+ }
186
+
187
+ if ( volume < 0 ) {
188
+ volume = 0;
189
+ }
190
+ if ( volume > 100 ) {
191
+ volume = 100;
192
+ }
193
+
194
+ this.volume = volume;
195
+ this.sound.volume = volume / 100;
196
+ return this;
197
+ };
198
+
199
+ this.getVolume = function() {
200
+ if ( !supported ) {
201
+ return this;
202
+ }
203
+
204
+ return this.volume;
205
+ };
206
+
207
+ this.increaseVolume = function( value ) {
208
+ return this.setVolume( this.volume + ( value || 1 ) );
209
+ };
210
+
211
+ this.decreaseVolume = function( value ) {
212
+ return this.setVolume( this.volume - ( value || 1 ) );
213
+ };
214
+
215
+ this.setTime = function( time ) {
216
+ if ( !supported ) {
217
+ return this;
218
+ }
219
+
220
+ this.whenReady( function() {
221
+ this.sound.currentTime = time;
222
+ });
223
+ return this;
224
+ };
225
+
226
+ this.getTime = function() {
227
+ if ( !supported ) {
228
+ return null;
229
+ }
230
+
231
+ var time = Math.round( this.sound.currentTime * 100 ) / 100;
232
+ return isNaN( time ) ? buzz.defaults.placeholder : time;
233
+ };
234
+
235
+ this.setPercent = function( percent ) {
236
+ if ( !supported ) {
237
+ return this;
238
+ }
239
+
240
+ return this.setTime( buzz.fromPercent( percent, this.sound.duration ) );
241
+ };
242
+
243
+ this.getPercent = function() {
244
+ if ( !supported ) {
245
+ return null;
246
+ }
247
+
248
+ var percent = Math.round( buzz.toPercent( this.sound.currentTime, this.sound.duration ) );
249
+ return isNaN( percent ) ? buzz.defaults.placeholder : percent;
250
+ };
251
+
252
+ this.setSpeed = function( duration ) {
253
+ if ( !supported ) {
254
+ return this;
255
+ }
256
+
257
+ this.sound.playbackRate = duration;
258
+ };
259
+
260
+ this.getSpeed = function() {
261
+ if ( !supported ) {
262
+ return null;
263
+ }
264
+
265
+ return this.sound.playbackRate;
266
+ };
267
+
268
+ this.getDuration = function() {
269
+ if ( !supported ) {
270
+ return null;
271
+ }
272
+
273
+ var duration = Math.round( this.sound.duration * 100 ) / 100;
274
+ return isNaN( duration ) ? buzz.defaults.placeholder : duration;
275
+ };
276
+
277
+ this.getPlayed = function() {
278
+ if ( !supported ) {
279
+ return null;
280
+ }
281
+
282
+ return timerangeToArray( this.sound.played );
283
+ };
284
+
285
+ this.getBuffered = function() {
286
+ if ( !supported ) {
287
+ return null;
288
+ }
289
+
290
+ return timerangeToArray( this.sound.buffered );
291
+ };
292
+
293
+ this.getSeekable = function() {
294
+ if ( !supported ) {
295
+ return null;
296
+ }
297
+
298
+ return timerangeToArray( this.sound.seekable );
299
+ };
300
+
301
+ this.getErrorCode = function() {
302
+ if ( supported && this.sound.error ) {
303
+ return this.sound.error.code;
304
+ }
305
+ return 0;
306
+ };
307
+
308
+ this.getErrorMessage = function() {
309
+ if ( !supported ) {
310
+ return null;
311
+ }
312
+
313
+ switch( this.getErrorCode() ) {
314
+ case 1:
315
+ return 'MEDIA_ERR_ABORTED';
316
+ case 2:
317
+ return 'MEDIA_ERR_NETWORK';
318
+ case 3:
319
+ return 'MEDIA_ERR_DECODE';
320
+ case 4:
321
+ return 'MEDIA_ERR_SRC_NOT_SUPPORTED';
322
+ default:
323
+ return null;
324
+ }
325
+ };
326
+
327
+ this.getStateCode = function() {
328
+ if ( !supported ) {
329
+ return null;
330
+ }
331
+
332
+ return this.sound.readyState;
333
+ };
334
+
335
+ this.getStateMessage = function() {
336
+ if ( !supported ) {
337
+ return null;
338
+ }
339
+
340
+ switch( this.getStateCode() ) {
341
+ case 0:
342
+ return 'HAVE_NOTHING';
343
+ case 1:
344
+ return 'HAVE_METADATA';
345
+ case 2:
346
+ return 'HAVE_CURRENT_DATA';
347
+ case 3:
348
+ return 'HAVE_FUTURE_DATA';
349
+ case 4:
350
+ return 'HAVE_ENOUGH_DATA';
351
+ default:
352
+ return null;
353
+ }
354
+ };
355
+
356
+ this.getNetworkStateCode = function() {
357
+ if ( !supported ) {
358
+ return null;
359
+ }
360
+
361
+ return this.sound.networkState;
362
+ };
363
+
364
+ this.getNetworkStateMessage = function() {
365
+ if ( !supported ) {
366
+ return null;
367
+ }
368
+
369
+ switch( this.getNetworkStateCode() ) {
370
+ case 0:
371
+ return 'NETWORK_EMPTY';
372
+ case 1:
373
+ return 'NETWORK_IDLE';
374
+ case 2:
375
+ return 'NETWORK_LOADING';
376
+ case 3:
377
+ return 'NETWORK_NO_SOURCE';
378
+ default:
379
+ return null;
380
+ }
381
+ };
382
+
383
+ this.set = function( key, value ) {
384
+ if ( !supported ) {
385
+ return this;
386
+ }
387
+
388
+ this.sound[ key ] = value;
389
+ return this;
390
+ };
391
+
392
+ this.get = function( key ) {
393
+ if ( !supported ) {
394
+ return null;
395
+ }
396
+
397
+ return key ? this.sound[ key ] : this.sound;
398
+ };
399
+
400
+ this.bind = function( types, func ) {
401
+ if ( !supported ) {
402
+ return this;
403
+ }
404
+
405
+ types = types.split( ' ' );
406
+
407
+ var that = this,
408
+ efunc = function( e ) { func.call( that, e ); };
409
+
410
+ for( var t = 0; t < types.length; t++ ) {
411
+ var type = types[ t ],
412
+ idx = type;
413
+ type = idx.split( '.' )[ 0 ];
414
+
415
+ events.push( { idx: idx, func: efunc } );
416
+ this.sound.addEventListener( type, efunc, true );
417
+ }
418
+ return this;
419
+ };
420
+
421
+ this.unbind = function( types ) {
422
+ if ( !supported ) {
423
+ return this;
424
+ }
425
+
426
+ types = types.split( ' ' );
427
+
428
+ for( var t = 0; t < types.length; t++ ) {
429
+ var idx = types[ t ],
430
+ type = idx.split( '.' )[ 0 ];
431
+
432
+ for( var i = 0; i < events.length; i++ ) {
433
+ var namespace = events[ i ].idx.split( '.' );
434
+ if ( events[ i ].idx == idx || ( namespace[ 1 ] && namespace[ 1 ] == idx.replace( '.', '' ) ) ) {
435
+ this.sound.removeEventListener( type, events[ i ].func, true );
436
+ // remove event
437
+ events.splice(i, 1);
438
+ }
439
+ }
440
+ }
441
+ return this;
442
+ };
443
+
444
+ this.bindOnce = function( type, func ) {
445
+ if ( !supported ) {
446
+ return this;
447
+ }
448
+
449
+ var that = this;
450
+
451
+ eventsOnce[ pid++ ] = false;
452
+ this.bind( pid + type, function() {
453
+ if ( !eventsOnce[ pid ] ) {
454
+ eventsOnce[ pid ] = true;
455
+ func.call( that );
456
+ }
457
+ that.unbind( pid + type );
458
+ });
459
+ };
460
+
461
+ this.trigger = function( types ) {
462
+ if ( !supported ) {
463
+ return this;
464
+ }
465
+
466
+ types = types.split( ' ' );
467
+
468
+ for( var t = 0; t < types.length; t++ ) {
469
+ var idx = types[ t ];
470
+
471
+ for( var i = 0; i < events.length; i++ ) {
472
+ var eventType = events[ i ].idx.split( '.' );
473
+ if ( events[ i ].idx == idx || ( eventType[ 0 ] && eventType[ 0 ] == idx.replace( '.', '' ) ) ) {
474
+ var evt = document.createEvent('HTMLEvents');
475
+ evt.initEvent( eventType[ 0 ], false, true );
476
+ this.sound.dispatchEvent( evt );
477
+ }
478
+ }
479
+ }
480
+ return this;
481
+ };
482
+
483
+ this.fadeTo = function( to, duration, callback ) {
484
+ if ( !supported ) {
485
+ return this;
486
+ }
487
+
488
+ if ( duration instanceof Function ) {
489
+ callback = duration;
490
+ duration = buzz.defaults.duration;
491
+ } else {
492
+ duration = duration || buzz.defaults.duration;
493
+ }
494
+
495
+ var from = this.volume,
496
+ delay = duration / Math.abs( from - to ),
497
+ that = this;
498
+ this.play();
499
+
500
+ function doFade() {
501
+ setTimeout( function() {
502
+ if ( from < to && that.volume < to ) {
503
+ that.setVolume( that.volume += 1 );
504
+ doFade();
505
+ } else if ( from > to && that.volume > to ) {
506
+ that.setVolume( that.volume -= 1 );
507
+ doFade();
508
+ } else if ( callback instanceof Function ) {
509
+ callback.apply( that );
510
+ }
511
+ }, delay );
512
+ }
513
+ this.whenReady( function() {
514
+ doFade();
515
+ });
516
+
517
+ return this;
518
+ };
519
+
520
+ this.fadeIn = function( duration, callback ) {
521
+ if ( !supported ) {
522
+ return this;
523
+ }
524
+
525
+ return this.setVolume(0).fadeTo( 100, duration, callback );
526
+ };
527
+
528
+ this.fadeOut = function( duration, callback ) {
529
+ if ( !supported ) {
530
+ return this;
531
+ }
532
+
533
+ return this.fadeTo( 0, duration, callback );
534
+ };
535
+
536
+ this.fadeWith = function( sound, duration ) {
537
+ if ( !supported ) {
538
+ return this;
539
+ }
540
+
541
+ this.fadeOut( duration, function() {
542
+ this.stop();
543
+ });
544
+
545
+ sound.play().fadeIn( duration );
546
+
547
+ return this;
548
+ };
549
+
550
+ this.whenReady = function( func ) {
551
+ if ( !supported ) {
552
+ return null;
553
+ }
554
+
555
+ var that = this;
556
+ if ( this.sound.readyState === 0 ) {
557
+ this.bind( 'canplay.buzzwhenready', function() {
558
+ func.call( that );
559
+ });
560
+ } else {
561
+ func.call( that );
562
+ }
563
+ };
564
+
565
+ // privates
566
+ function timerangeToArray( timeRange ) {
567
+ var array = [],
568
+ length = timeRange.length - 1;
569
+
570
+ for( var i = 0; i <= length; i++ ) {
571
+ array.push({
572
+ start: timeRange.start( length ),
573
+ end: timeRange.end( length )
574
+ });
575
+ }
576
+ return array;
577
+ }
578
+
579
+ function getExt( filename ) {
580
+ return filename.split('.').pop();
581
+ }
582
+
583
+ function addSource( sound, src ) {
584
+ var source = document.createElement( 'source' );
585
+ source.src = src;
586
+ if ( buzz.types[ getExt( src ) ] ) {
587
+ source.type = buzz.types[ getExt( src ) ];
588
+ }
589
+ sound.appendChild( source );
590
+ }
591
+
592
+ // init
593
+ if ( supported && src ) {
594
+
595
+ for(var i in buzz.defaults ) {
596
+ if(buzz.defaults.hasOwnProperty(i)) {
597
+ options[ i ] = options[ i ] || buzz.defaults[ i ];
598
+ }
599
+ }
600
+
601
+ this.sound = document.createElement( 'audio' );
602
+
603
+ if ( src instanceof Array ) {
604
+ for( var j in src ) {
605
+ if(src.hasOwnProperty(j)) {
606
+ addSource( this.sound, src[ j ] );
607
+ }
608
+ }
609
+ } else if ( options.formats.length ) {
610
+ for( var k in options.formats ) {
611
+ if(options.formats.hasOwnProperty(k)) {
612
+ addSource( this.sound, src + '.' + options.formats[ k ] );
613
+ }
614
+ }
615
+ } else {
616
+ addSource( this.sound, src );
617
+ }
618
+
619
+ if ( options.loop ) {
620
+ this.loop();
621
+ }
622
+
623
+ if ( options.autoplay ) {
624
+ this.sound.autoplay = 'autoplay';
625
+ }
626
+
627
+ if ( options.preload === true ) {
628
+ this.sound.preload = 'auto';
629
+ } else if ( options.preload === false ) {
630
+ this.sound.preload = 'none';
631
+ } else {
632
+ this.sound.preload = options.preload;
633
+ }
634
+
635
+ this.setVolume( options.volume );
636
+
637
+ buzz.sounds.push( this );
638
+ }
639
+ },
640
+
641
+ group: function( sounds ) {
642
+ sounds = argsToArray( sounds, arguments );
643
+
644
+ // publics
645
+ this.getSounds = function() {
646
+ return sounds;
647
+ };
648
+
649
+ this.add = function( soundArray ) {
650
+ soundArray = argsToArray( soundArray, arguments );
651
+ for( var a = 0; a < soundArray.length; a++ ) {
652
+ sounds.push( soundArray[ a ] );
653
+ }
654
+ };
655
+
656
+ this.remove = function( soundArray ) {
657
+ soundArray = argsToArray( soundArray, arguments );
658
+ for( var a = 0; a < soundArray.length; a++ ) {
659
+ for( var i = 0; i < sounds.length; i++ ) {
660
+ if ( sounds[ i ] == soundArray[ a ] ) {
661
+ delete sounds[ i ];
662
+ break;
663
+ }
664
+ }
665
+ }
666
+ };
667
+
668
+ this.load = function() {
669
+ fn( 'load' );
670
+ return this;
671
+ };
672
+
673
+ this.play = function() {
674
+ fn( 'play' );
675
+ return this;
676
+ };
677
+
678
+ this.togglePlay = function( ) {
679
+ fn( 'togglePlay' );
680
+ return this;
681
+ };
682
+
683
+ this.pause = function( time ) {
684
+ fn( 'pause', time );
685
+ return this;
686
+ };
687
+
688
+ this.stop = function() {
689
+ fn( 'stop' );
690
+ return this;
691
+ };
692
+
693
+ this.mute = function() {
694
+ fn( 'mute' );
695
+ return this;
696
+ };
697
+
698
+ this.unmute = function() {
699
+ fn( 'unmute' );
700
+ return this;
701
+ };
702
+
703
+ this.toggleMute = function() {
704
+ fn( 'toggleMute' );
705
+ return this;
706
+ };
707
+
708
+ this.setVolume = function( volume ) {
709
+ fn( 'setVolume', volume );
710
+ return this;
711
+ };
712
+
713
+ this.increaseVolume = function( value ) {
714
+ fn( 'increaseVolume', value );
715
+ return this;
716
+ };
717
+
718
+ this.decreaseVolume = function( value ) {
719
+ fn( 'decreaseVolume', value );
720
+ return this;
721
+ };
722
+
723
+ this.loop = function() {
724
+ fn( 'loop' );
725
+ return this;
726
+ };
727
+
728
+ this.unloop = function() {
729
+ fn( 'unloop' );
730
+ return this;
731
+ };
732
+
733
+ this.setTime = function( time ) {
734
+ fn( 'setTime', time );
735
+ return this;
736
+ };
737
+
738
+ this.setduration = function( duration ) {
739
+ fn( 'setduration', duration );
740
+ return this;
741
+ };
742
+
743
+ this.set = function( key, value ) {
744
+ fn( 'set', key, value );
745
+ return this;
746
+ };
747
+
748
+ this.bind = function( type, func ) {
749
+ fn( 'bind', type, func );
750
+ return this;
751
+ };
752
+
753
+ this.unbind = function( type ) {
754
+ fn( 'unbind', type );
755
+ return this;
756
+ };
757
+
758
+ this.bindOnce = function( type, func ) {
759
+ fn( 'bindOnce', type, func );
760
+ return this;
761
+ };
762
+
763
+ this.trigger = function( type ) {
764
+ fn( 'trigger', type );
765
+ return this;
766
+ };
767
+
768
+ this.fade = function( from, to, duration, callback ) {
769
+ fn( 'fade', from, to, duration, callback );
770
+ return this;
771
+ };
772
+
773
+ this.fadeIn = function( duration, callback ) {
774
+ fn( 'fadeIn', duration, callback );
775
+ return this;
776
+ };
777
+
778
+ this.fadeOut = function( duration, callback ) {
779
+ fn( 'fadeOut', duration, callback );
780
+ return this;
781
+ };
782
+
783
+ // privates
784
+ function fn() {
785
+ var args = argsToArray( null, arguments ),
786
+ func = args.shift();
787
+
788
+ for( var i = 0; i < sounds.length; i++ ) {
789
+ sounds[ i ][ func ].apply( sounds[ i ], args );
790
+ }
791
+ }
792
+
793
+ function argsToArray( array, args ) {
794
+ return ( array instanceof Array ) ? array : Array.prototype.slice.call( args );
795
+ }
796
+ },
797
+
798
+ all: function() {
799
+ return new buzz.group( buzz.sounds );
800
+ },
801
+
802
+ isSupported: function() {
803
+ return !!buzz.el.canPlayType;
804
+ },
805
+
806
+ isOGGSupported: function() {
807
+ return !!buzz.el.canPlayType && buzz.el.canPlayType( 'audio/ogg; codecs="vorbis"' );
808
+ },
809
+
810
+ isWAVSupported: function() {
811
+ return !!buzz.el.canPlayType && buzz.el.canPlayType( 'audio/wav; codecs="1"' );
812
+ },
813
+
814
+ isMP3Supported: function() {
815
+ return !!buzz.el.canPlayType && buzz.el.canPlayType( 'audio/mpeg;' );
816
+ },
817
+
818
+ isAACSupported: function() {
819
+ return !!buzz.el.canPlayType && ( buzz.el.canPlayType( 'audio/x-m4a;' ) || buzz.el.canPlayType( 'audio/aac;' ) );
820
+ },
821
+
822
+ toTimer: function( time, withHours ) {
823
+ var h, m, s;
824
+ h = Math.floor( time / 3600 );
825
+ h = isNaN( h ) ? '--' : ( h >= 10 ) ? h : '0' + h;
826
+ m = withHours ? Math.floor( time / 60 % 60 ) : Math.floor( time / 60 );
827
+ m = isNaN( m ) ? '--' : ( m >= 10 ) ? m : '0' + m;
828
+ s = Math.floor( time % 60 );
829
+ s = isNaN( s ) ? '--' : ( s >= 10 ) ? s : '0' + s;
830
+ return withHours ? h + ':' + m + ':' + s : m + ':' + s;
831
+ },
832
+
833
+ fromTimer: function( time ) {
834
+ var splits = time.toString().split( ':' );
835
+ if ( splits && splits.length == 3 ) {
836
+ time = ( parseInt( splits[ 0 ], 10 ) * 3600 ) + ( parseInt(splits[ 1 ], 10 ) * 60 ) + parseInt( splits[ 2 ], 10 );
837
+ }
838
+ if ( splits && splits.length == 2 ) {
839
+ time = ( parseInt( splits[ 0 ], 10 ) * 60 ) + parseInt( splits[ 1 ], 10 );
840
+ }
841
+ return time;
842
+ },
843
+
844
+ toPercent: function( value, total, decimal ) {
845
+ var r = Math.pow( 10, decimal || 0 );
846
+
847
+ return Math.round( ( ( value * 100 ) / total ) * r ) / r;
848
+ },
849
+
850
+ fromPercent: function( percent, total, decimal ) {
851
+ var r = Math.pow( 10, decimal || 0 );
852
+
853
+ return Math.round( ( ( total / 100 ) * percent ) * r ) / r;
854
+ }
855
+ };
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buzz-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Charles Lowell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ description: use buzz.js in rails
31
+ email:
32
+ - cowboyd@thefrontside.net
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - buzz-rails.gemspec
43
+ - lib/buzz-rails.rb
44
+ - lib/buzz-rails/version.rb
45
+ - vendor/assets/javascripts/buzz.js
46
+ homepage: http://buzz.jaysalvat.com
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.24
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Buzz is a jQuery like API for using HTML5 Audio
70
+ test_files: []